# Export VBA code to Word but keep color format



## Rick85 (May 25, 2010)

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


----------



## Derek Brown (May 27, 2010)

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 (Aug 17, 2015)

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 (Aug 17, 2015)

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!


----------



## kordelski (Aug 18, 2016)

Rick85 said:


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




Try the VBA script from Chris Macro:

Format VBA Code Inside A Microsoft Word Document


----------



## Jon Peltier (Feb 10, 2019)

marcnz said:


> 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.
> 
> ...



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.


----------



## mark91345 (Jul 16, 2019)

Thank you. That info worked perfectly for me.


----------

