Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick example showing how to extract VBA macros to files using olevba (Python 2 or 3)
# Quick example showing how to extract VBA macros to files using olevba
# works with python 2 or 3
# ref: https://github.com/decalage2/oletools/wiki/olevba#extract-vba-macro-source-code
import sys
if sys.version_info[0] <= 2:
# Python 2.x
from oletools.olevba import VBA_Parser
else:
# Python 3.x
from oletools.olevba3 import VBA_Parser
vbaparser = VBA_Parser(sys.argv[1])
for (filename, stream_path, vba_filename, vba_code) in vbaparser.extract_macros():
print('-'*79)
print('Filename: %s' % filename)
print('OLE stream: %s' % stream_path)
print('VBA filename: %s' % vba_filename)
with open(vba_filename, 'wb') as f:
f.write(vba_code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment