Export VBA code to Word but keep color format

Rick85

New Member
Joined
Apr 7, 2010
Messages
11
Hi guys!

I was wondering how can i export VBA code to a text editor like word, keeping the color formats.

Does anyone know?

Thanks in advance
Rick
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Derek Brown

Well-known Member
Joined
Dec 26, 2005
Messages
2,390
Are you trying to this so that you can print it?
If you mean that the reserved words, comments etc. need to be colored then you will not be able to that (or if so, it is something that I have not come across).
I use two software products when I want to do this - either (a) EditPad Pro or (b) VBA Code Print.
EditPad Pro (impressive text editor):
http://www.just-great-software.com/
VBA Code Print (print utility):
http://www.ozgrid.com/Services/print-vba-code.htm
 

marcnz

New Member
Joined
Dec 19, 2012
Messages
13
I know this is old, but the question remain.

I have to write technical documentation for the company I work and develop for and it has to be in Word 2010.

I do use Notepad++ extensively for other things, but my document must end up in Word.

So the question remains:

How can I copy VBA code from the VB Editor in either MS Excel or MS Access into a Word document and keep its full formatting (font and coloring)?

Thank you for helping.
 

marcnz

New Member
Joined
Dec 19, 2012
Messages
13
I found the perfect solution to this question from another forum:
How do you display code snippets in MS Word preserving format and syntax highlighting? - Stack Overflow

Keep in mind that the font pasted into Word will be the font on the Notepad++ document.

If another font is required (smaller for example), you have to change it first in Notepad++/Settings/Style Configurator and make sure it is applied. I had to check the "Global xxx" boxes.

Really nice! Very easy.

Still, one would think that Microsoft would have thought about this type of request and needs. A special "Style" built-in that would automatically reproduce the VBA font/color would have been really good and surely a piece of cake to develop and implement in a MS developer genius brain!
 

Jon Peltier

MrExcel MVP
Joined
May 14, 2003
Messages
4,879
Office Version
365
Platform
Windows, MacOS
I have to write technical documentation for the company I work and develop for and it has to be in Word 2010.

I do use Notepad++ extensively for other things, but my document must end up in Word.

So the question remains:

How can I copy VBA code from the VB Editor in either MS Excel or MS Access into a Word document and keep its full formatting (font and coloring)?
3+ years later, but here's my approach. The dinosaur in me sometimes still likes to work with pencil and ink on code printouts.

Copy the VBA, paste into a new file in Notepad++ aka NPP.

Change the language to VB (Alt-L for Language menu > V).

Use the NppExport plugin (part of the standard NPP install) to copy the RTF to the clipboard. Alt-P for Plugins menu, then arrow up or down to select NppExport, right arrow to choices, up or down arrow to Copy RTF to Clipboard.

Switch to Word, open a new file (I've made my own Word template that's got some formatting plus a small Word VBA procedure that selects everything and applies the font and size I want, Consolas 8pt), and paste.

I'd like to automate the NPP piece, but as it is, it takes just a few seconds per module, less time than it takes to retrieve the printout from the printer.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,379
Messages
5,486,525
Members
407,550
Latest member
LucasBordure

This Week's Hot Topics

Top