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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

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,889
Messages
5,489,543
Members
407,697
Latest member
Lotte_4

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top