u/kay-jay-dubya

ChibiArc — ZIP, 7‑Zip, TAR, ISO support in 64‑bit VBA (AES included)
▲ 15 r/vba

ChibiArc — ZIP, 7‑Zip, TAR, ISO support in 64‑bit VBA (AES included)

So I made a thing. That thing is ChibiArc.

What is ChibiArc?

ChibiArc is a single‑class VBA module for reading and writing archive files (e.g.: ZIP, 7‑Zip, all manner of TAR variants, ISO, RAR (read‑only)) from 64‑bit Office applications. No third‑party DLLs, no COM objects, no magic spells. It uses archiveint.dll (Microsoft's implementation of libarchive), which ships with Windows 10+, and AES encryption is done via Win32 APIs.

If you've ever tried to zip/unzip files from VBA and ended up in a swamp of Shell calls, PowerShell hacks, or "copy to temp folder and wait… and then wait a bit more…", then this is for you.

How to use it?

Dim arc As New ChibiArc

' Create a ZIP with AES-256
If arc.NewFile("C:\output\secure.zip") Then
  arc.Encryption = aeAes256
  arc.PassPhrase = "how now brown cow"
  arc.Add "C:\reports\"              ' entire folder, recursive
  arc.Add "C:\data\somefile.txt"     ' single file
  arc.SaveFile                       ' closes automatically
End If

' Read it back
Set arc = New ChibiArc
If arc.OpenFile("C:\output\secure.zip", "how now brown cow") Then
  Debug.Print "Files: " & arc.FileCount
  Dim entries As Variant
  entries = arc.Dir("*.txt")        ' wildcard support
  arc.ExtractAll "C:\extracthere\"
  arc.CloseFile
End If

Encryption

ChibiArc supports both ZipCrypto and AES (128/192/256). No, they are not interchangeable.

ZipCrypto exists purely because Windows Explorer can handle it. Frankly, that's about all Explorer can handle. Critically, Explorer cannot extract AES‑encrypted ZIPs.

ZipCrypto is apparently cryptographically vintage. I haven't personally tested it, but the entire internet assures me it's disturbingly vulnerable. If you have strong feelings about this, please direct your concerns to Microsoft. As we all know, they are tremendously receptive and responsive to unsolicited feedback from random VBA developers. Famously so.

So in short, use AES‑256 for anything that matters. Use ZipCrypto only when Explorer compatibility is non‑negotiable.

Limitations

Full list is on GitHub, but the main one is that ChibiArc currently supports 64‑bit only. 32‑bit support is coming, but in the meantime I genuinely recommend wqweto's excellent ZipArchive: https://github.com/wqweto/ZipArchive/

As always, any bugs, blunders, oversights, and general acts of coding inelegance are entirely my own. Any accidental sparks of brilliance you find are almost certainly someone else’s. Namely:

The mascot, however, is all me. It was created entirely in Excel. Because of course it was.

MIT licensed. Feedback, bug reports, and telling me I've done something wrong are always met with varying degrees of appreciation, skepticism, and (mostly) good humour.

GitHub: https://github.com/KallunWillock/ChibiArc

u/kay-jay-dubya — 5 days ago
▲ 27 r/vba

ChibiEx - PDF rendering + OCR in VBA (no dependencies, API-based)

As foreshadowed in a previous comment some time ago, and in response to this post last week about automating screenshots of PDFs, I have finally uploaded the first release from my ChibiPDF project (class module: ChibiEx).

ChibiEx provides:

  1. PDF rendering to PNG images (usable directly in UserForm controls), and
  2. OCR-based text extraction from PDF pages using built-in Windows APIs.

What distinguishes this solution from all/most others is that - assuming that you are using VBA on Windows 10+ - there are no dependencies. This is important because I suspect that, like me, many of you use VBA in work environments that are similarly technologically locked-down, and so "Just use Python" or "Just install Adobe" is a non-starter with our respective IT departments.

Existing options

There are, of course, alternatives available to us:

  • Microsoft Word allows you to open PDF files, from which you could extract the text... assuming there is a text layer in the PDF. It can be quite slow though.
  • PowerQuery - definitely possible provided you have the PDF connector, though it can be tricky to wrangle if your PDF files are pages of pure text in non-tabular form.
  • Free third party software - I would ordinarily recommend XPDF tools, because it doesn't require installation. They are, however, binary files that simply will not be permitted on my work computer. I should add that I did actually upload an open source solution that results in an 64-bit DLL that uses the XPDF engine here (xpdf-dll).

Why are there no dependencies?

This is because both the PDF rendering and the OCR functionality comes built-in as part of the WinRT API set (Windows.Data.Pdf and Windows.Media.Ocr), which itself ships with Win10+, so all this class does is allow VBA users to leverage that functionality.

I came across the WinRT APIs that enables it while trawling through VBForums.com and ActiveVB.de. To that end, all credit should go to Frank Schuler (activevb.de) for all of his brilliant WinRT work; all bugs and mistakes are quite clearly my own.

How to use ChibiEx

Using it is (hopefully) straightforward enough. For example, to load a file, export all pages to PNG image files, and extract the text:

Dim pdf As New ChibiEx
If pdf.LoadFile("C:\Docs\Report.pdf") Then
  ' Render all pages
  pdf.ToFile "C:\Output\"       
  ' Extract text from the entire document     
  Debug.Print pdf.ExtractAllText() 
End If 

You can also target specific pages, ranges, or render directly to memory:

' Render a specific page 
pdf.ToFile "C:\Output\", 5   

' Render a range of pages 
pdf.ToFile "C:\Output\", 2, 10   

' Render specific pages 
pdf.ToFile "C:\Output\", Array(1, 5, 12)   

' Render to a StdPicture (for UserForms or Image controls) 
Dim pic As  StdPicture 
Set pic = pdf.ToPicture(1) ```   

Because the OCR engine is built-in, you can also use it purely for OCR on standard images, independent of any PDF:

Dim ocr As New ChibiEx
If ocr.RecogniseFile("C:\OCR\Scan.png") Then
  Debug.Print ocr.ResultText
End If 

ChibiPDF - Roadmap

I’m currently working on:

  • ChibiScribe: PDF generation from scratch (fully native PDF writer) - Given the multitude of ways to generate PDF files available to us in Office, this module is arguably less necessary, but I've enjoyed the process of making it.  It's also quite quick.
  • A “canonical” PDF text extraction parser (ie: parsing the raw PDF objects), though PDF internals are... 'character-building', I'm told...

The library is MIT licensed and available on GitHub: https://github.com/KallunWillock/ChibiPDF Feedback is always appreciated.

u/kay-jay-dubya — 27 days ago