Reputation: 19
I have a lot of code I wrote, for various different projects.
I want to save them in 1 file, to have like a "repository" of working code modules. So for new VBA projects I can copy the modules from there.
Is there a way to save the code files outside of the VBA editor? Like a text file or something like that?
Upvotes: 1
Views: 119
Reputation: 71177
Yes. Simply select Export File... from the Project Explorer toolwindow:
If you're using Rubberduck (disclaimer: I manage this OSS project), you can also do that from the Code Explorer toolwindow:
To use the exported module(s) in other VBA projects, you'll need to Import it back. You can do that one file at a time with the VBE's Project Explorer, or all files at once with Rubberduck's Code Explorer.
Or you can simply drag-and-drop the files into the Project Explorer.
Standard modules will have a .bas file extension; Class modules will have .cls; UserForm modules will have a .frm file and likely a .frx binary that needs to be in the same folder as the .frm for it to import back correctly.
Document modules (e.g. workbook and worksheet modules, like Sheet1
and ThisWorkbook
) can't be imported, but you can export them as .cls files from the Project Explorer, or as .doccls files from Rubberduck.
The reason Rubberduck exports document modules with a different file extension, is because they can't be imported back, so module and member attributes (which you can only discover by opening the exported files in a text editor e.g. Notepad++) can't be tweaked the same way normal class modules can.
Upvotes: 1