-
-
Save dsisnero/14040cf831083da24afe19da24013c72 to your computer and use it in GitHub Desktop.
extract all VBA modules from the given workbooks. Use full paths, and enable access to the vba project object model in excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def extract_vb_modules(paths) | |
require 'win32ole' | |
excel_app = WIN32OLE.new('Excel.Application') | |
excel_app.ScreenUpdating = false | |
excel_app.EnableEvents = false | |
excel_app.DisplayAlerts = false | |
#excel_app.Calculation = -4135 | |
paths.each do |path| | |
workbook = excel_app.Workbooks.open(path) | |
workbook.VBProject.VBComponents.each do |vb_component| | |
if vb_component.CodeModule.CountOfLines > 0 | |
vb_component.Export( | |
"#{File.dirname(path).gsub(/\//, "\\\\")}\\#{ | |
File.basename(path) + "_" + vb_component.codemodule.name}") | |
end | |
end | |
workbook.close | |
end | |
excel_app.quit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment