Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read VBA macros (or vbaProject.bin) of an Excel file without opening it in MS Excel [closed]

I would like to analyze Excel files, especially those which contain VBA programs inside. because I plan to run this analysis on lots of Excel files one by one, I don't want to open these files within Microsoft Excel to analyze them.

One difficulty is to find and parse the VBA macros of an Excel file. We know that an Excel file can be converted to .zip file which contains lots of .xml and vbaProject.bin, it is pretty certain that VBA macros are in vbaProject.bin. However, the problem is how to read it?

Does anyone know if there is any tool or API to find and parse the VBA macros?

Does anyone know if there is any tool or API to read vbaProject.bin?

like image 965
SoftTimur Avatar asked Jul 08 '13 21:07

SoftTimur


People also ask

How extract VBA code without opening Excel?

Run "officeparser.py --extract-macros <file>" to extract VBA code.

How do I run a macro in a closed workbook?

If you want to run the code while closing workbook each time, select Deactiviate from the right drop down list in the Code window, and copy the code you will run and paste between Private Sub Workbook_Deactivate() and End Sub.

Can Excel pull data from a closed workbook?

Extracting data from a closed file in another workbook is a common request by most of the excel user. They would like to pull or consolidate data from closed files; however, this is not possible.


2 Answers

There is a very large PDF from Microsoft which documents how to extract functions from the vbaproject.bin:

https://interoperability.blob.core.windows.net/files/MS-OVBA/%5bMS-OVBA%5d.pdf [Source]

This resource is current & available as of June 27, 2019. The event that this link goes stale (Microsoft periodically changes their permalink structure or otherwise alters how they implement their documentation/answer repositories, etc.), search for MS-OVBA.pdf.

Some additional information which may or may not be complimentary to the above:

http://www.codeproject.com/Articles/15216/Office-2007-bin-file-format

like image 105
David Zemens Avatar answered Sep 21 '22 10:09

David Zemens


Here's an article updated in 2017 that lists several tools for helping with this. I was able to extract the VBA code out of a vbaProject.bin using the OfficeMalScanner tool. Edit: some months after successfully using this tool, Windows is detecting malware in it. The link was www dot reconstructer dot org / code / OfficeMalScanner.zip. Use at your own risk - it worked for me to extract a bunch of needed VBA code from the project after the source was lost. Edit 2: per @HackSlash comment below, probably a false positive.

like image 26
pettys Avatar answered Sep 20 '22 10:09

pettys