PDA

View Full Version : [SOLVED] Exporting VBA Modules



Cyberdude
09-14-2005, 12:43 PM
Every so often I go through my workbooks and export all the modules to a sete of "module save" folders. If there's been a lot of changes, I also delete all modules and then import them to compress them. It just occurred to me that I don't know if I'm exporting the "Workbook" modules (the ones with "Workbook_Open" etc) when I do that. Should I be exporting something from the Workbook level?
I apparently did that at one time and created a ".cls" entry,
but I have no idea what's in it. :dunno

Jacob Hilderbrand
09-14-2005, 12:49 PM
You can just import it. It will import as a class module, then you can copy/paste the code into a sheet module or ThisWorkbook.

mvidas
09-14-2005, 12:54 PM
Hi CD,

The excel objects technically are class objects in VBAs eyes, which is why it is exporting them as .cls files. You can open them in notepad, the pertinent code is under the Attribute statements. If you wanted to export programatically, you could use:


Sub cyberdude()
Dim aComponent As Object, ExportPath As String
ExportPath = "C:\backup\" 'ends in "\"
For Each aComponent In ThisWorkbook.VBProject.VBComponents
Select Case aComponent.Type
Case 2, 100: aComponent.Export ExportPath & aComponent.Name & ".cls"
Case 1: aComponent.Export ExportPath & aComponent.Name & ".bas"
Case 3: aComponent.Export ExportPath & aComponent.Name & ".frm"
End Select
Next
End Sub

Matt

Cyberdude
09-14-2005, 01:29 PM
Thanx for the ideas and code, Guys. That's what I wanted to know.