Tom’s Tutorials For Excel: Exporting VBA Module Code to a Text File
Here’s a quick way to export all the VBA code from a workbook module, assuming for example:
• The module of interest is named Module1.
• The text file that will receive this code is named “YourFileName.txt”.
• “YourFileName.txt” is located in the folder path C:\YourFilePath\.
• “YourFileName.txt” is closed and you want it to stay closed.
• I used Notepad as the text editor application for the text file.
First, for the workbook holding the module of interest, open that workbook and hit
Alt+F11 to go into the VBE. From the menu bar click
Tools > References, and establish a reference to
Microsoft Visual Basic For Applications Extensibility 5.3.
Ctrl+G to open the Immediate window.
Then, type in or copy and paste this single line of code into the Immediate window:
Note, I show the single line of code as two lines here, so the entire code can be seen on this web page by all internet browsers. Really, there is no line break, so be sure to place it all into the Immediate window on one continuous line as shown in the next picture:
Finally, with the cursor in the Immediate window, and blinking somewhere in or on that line of code you typed or copied and pasted, hit the
The copy is very fast and looks like nothing happened, although the code from Module1 of the active workbook transferred to that closed text file.
The ref to VBA Extensibility 5.3 beforehand is required, but it only needs to be done once.