asked on
Export all vba modules from outlook vbaproject.otm
I found bunches of code that will automate export for Excel modules, but no luck for Outlook.
I even found a 2004 post from the famous Sue Mosher saying she did it manually when needed.
I have a solution but it requires several manual steps, but I hope somebody has an easier way.
My solution is to use Outlook IDE control P then selected Code and "Current Project". Setup used "Microsoft Print to PDF" with 11x15 landscape (long lines of code won't split).
I also tried "print to file" but that did not seem to work.
After creating the 298 page PDF, I opened it with Foxit Reader and Saved as TXT.
The resulting TXT looks pretty good and a simple program could create multiple BAS modules. But before I do that I want to see if anybody here has already done something similar.
Each of my TXT pages start with 4 lines that look like this:
----------------------- Page 148-----------------------
2nd line is always blank.
mdlMicrosecondTimer - 8 3rd line has the module's name and page number
4th line is always blank.
subsequent lines have the actual code
ReDim Preserve SwNextSlowestCase(0 To ixSegment)
ixSegment = Ixsegment + 1
etc
etc
ASKER
When I used Text Printer, 11 x 17 wasn't available so I chose Tabloid which is supposedly the same as 11 x 17. Any line longer than 170 characters was word wrapped to the second line.
For instance column 170 occurs right before 2)blah in the following line of code.
exit_routine: msg = "This product has 2 features " & vbcrlf & " 1) blah " & vbcrlf & " 2)blah blah"
When I used PDF, I chose 11 x 17 landscape and none of my lines of code word wrapped even when they were 210 characters long.
I suspect this is because the PDF printer supports proportional fonts and the generic printer does not.
This complicates the clean up program a little. I was worried that the generic printer might do an RTrim on the 170 lines, but that does not appear to be the case. The following should probably work 99.9% of the time
if len(thisline) = 170 and right(thisline) <> "" then
thisline = thisline & Nextline
discard Nextline
end if
Do you know of any Generic Text Printer drivers that might support custom paper sizes?
ASKER
If somebody can find a alternative generic text printer that allows custom forms, I would be thrilled.
It turns out my cleanup program cannot be simple. Right now it screws up on this 3 lines of code
line1: I = I +3714 ' comment that ends exactly at column 170
line2: I = 2* I
line3: I = I +3714 ' comment that ends in column 123line4: I = 2* I
If I print that to generic text printer then review it with a hex editor there is no way tell if it is 3 lines of code or 4 lines of code
This is pathological, and 99.9% of the time my program would work, but I hate programs that almost work.
Instead, I am back to my original solution of a pdf printer. Plus, I just used Pdffactory to make a custom form 8.5 inches high by 40 inches wide which should never ever do word wrap. 99.99999% reliable I can live with.
The cumbersome steps only add about 3 minutes to my manual process. Seems worth it for a more reliable. solution
ASKER
On my windows 10 machine I could not find "printer servers" under devices as printers. Here is how I did it.
Start > "Print management" which opened a Microsoft console
expand "printer servers" which showed "cpu123" which is my laptop computer
Right click on cpu123 > properties
click on "Forms" tab and followed you instructions
Forms tab
•I selected Folio existing form to start from
•Clicked on Create a New Form
•Changed form name to Folio 50x50
•Set the Width to 50in and height 50 in (that way landscape vs portrait does not matter)
•Clicked OK button
Start > devices and printers > add a printer >
Click "the printer I want is not listed"
Select "Add a local printer or network printer with manual settings" >next
Use an existing port: FILE:(Print to file) > Next
Wait a minute while drop downs populate
Manufacturer: Generic
Printers: Generic / Text only
> Next > Use the driver that is currently Installed > next
I used "Print to file" as my printer name.
Pretty slick.
Thanks a bunch
ASKER
ASKER
You probably know how to tell Excel, Word, and Outlook to print onto many different forms such as "Letter" or "Legal".
The following procedure shows how to add a new form name "Folio 50x50" that is useful for printing VBA code to a file. There are 3 main steps.
1) create a form named "Folio 50x50" which is 50 inches high and 50 inches wide.
2) create print driver name "Print to File".
3) print Outlook VBA code to a file using the "Print to File" printer driver and the "Folio 50x50" form.
Thereafter, the "Print to File" driver can be used to print from virtually any Windows application.
STEP 1) Create a form named Folio 50x50.
Start > "Print management" which opened a Microsoft console
expand "printer servers" which showed "cpu123" which is my laptop computer
Right click on cpu123 > properties
click on "Forms" tab and followed you instructions
Forms tab
•Turn on "Create a New Form" then change Form Name to be "Folio 50x50"
•Set the Width to 50in and height 50 in (that way landscape vs portrait does not matter)
•Clicked OK button
Step 2) Create a "Print to File" printer.
Please note, several of the follow steps will pause for up to a minute while dropdown menus are populated.
Start > devices and printers > add a printer >
(or on some version of windows) Start > Printers and Scanners > Add a Printer or Scanner
Click "the printer I want is not listed"
Select "Add a local printer or network printer with manual settings" >next
Use an existing port: FILE:(Print to file) > Next < ===== THIS CORRECTS THE FEB 2017 SOLUTION.
Manufacturer: Generic
Printers: Generic / Text only (sometimes you'll have several choices. I took the topmost.)
> Next > Use the driver that is currently Installed > next
I used "Print to file" as my printer.
step 3) Use the following steps to print the project
Open Outlook > F11 to vba > Ctrl P to open print dialog
Turn on "Current Project" and "Code" radio buttons then click "Setup". (Do NOT turn on the "Print to File" checkbox)
Select "Print to file" from the printer Name dropdown
Select "Folio 50x50" from the Size dropdown.
Click Ok to start the print
Enter the full path for the desired output. For instance c:\temp\printout.prn
Hope this helps future researchers.
rberke
ASKER
When you print vba code to a file ofter a single 120 character line will print as if there were two lines
The following June 29, 2023 documentation is an improved version showing how to avoid line wrapping.
You probably know how to tell Excel, Word, and Outlook to print onto Printer Forms such as "Letter" or "Legal".
The following procedure shows how to add a new Printer Form name "Folio 50x50inch" that is useful for printing VBA code to a file. There are 3 main steps.
Step 1) create a form named "Folio 50x50inch" which is 50 inches high and 50 inches wide.
Step 2) create print driver name "Print to 50x50inch file".
Step 3) print Outlook or Excel VBA code to a file using the "Print to 50x50inch file". printer driver.
Thereafter, any Windows application can print to the new printer. (The results be great for .txt files and terrible for MS Word .doc files.)
STEP 1) Create a form named Folio 50x50Inch.
Start > "Printers & scanners"
Scroll down to "Related Settings" (on some Windows versions Related Settings is on the right side of the screen)
Click "print server properties" then click on "Forms" tab
Turn on "create a new form" then change Form Name to be "Folio 50x50inch"
Set the Width and Height to 50in (that way landscape vs portrait does not matter
Clicked OK button
Step 2) Create a "Print to 50x50inch File" printer.
Please note, several of the following steps will pause for up to a minute while dropdown menus are populated.
Start > devices and printers > add a printer >
(or on some version of windows Start > Printers and Scanners > Add a Printer or Scanner
Click "the printer I want is not listed"
Select "Add a local printer or network printer with manual settings" >next
Use an existing port: FILE:(Print to file) > Next
Manufacturer: Generic
Printers: Generic / Text only 10.0.16299.15 (if there are other choices use the first.)
> Next > Use the driver that is currently Installed > next
Start > devices and printers > click on previously created “Print to 50x50inch file”
On windows 10 & 11 Manage > Printing Preferences
On windows 7: Right click > Printing Preferencs
Select: Portrait > Advanced > Paper size: Folio 50x50inch > Ok > Ok
step 3) Use the following steps to print the project
Open Outlook or Excel > F11 to vba > Ctrl P to open print dialog
Turn on "Current Project" and "Code" radio buttons then click "Setup". (Do NOT turn on the "Print to File" checkbox)
Select "Print to Folio 50x50inch file" from the printer Name dropdown
Select "Folio 50x50inch" from the Size dropdown.
Click Ok to start the print
Enter the full path for the desired output. For instance c:\temp\printout.prn
Please note, the new printer will do a terrible job of printing MS Word documents and excel spreadsheets.
Hope this helps future researchers.
rberke
First the bad news:
The VBIDE object isn't exposed in the Outlook VBA object model. This is for security sake, the thinking being that since Outlook is typically directly connected to the internet, and constantly processing foreign emails that could contain malware, allowing programmatic access to the VBIDE object could be a major exploit. So no way to do it in code...
Now the good news:
With a little creativity and trial and error you should be able to split that if needed, there are very minimal headers for each part that have "XXXXXX - nn" on a line, where XXXXXX is a module name, and nn a segment number.
~bp