Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Pretty print VBA code?

How do you copy VBA code into a Word document and retain the VBA editor color scheme?

like image 288
mraviator Avatar asked Apr 05 '10 11:04

mraviator


1 Answers

You can use Notepad++ to accomplish this in three ways. Just so you know, Notepad++ is a more advanced version of Notepad, which supports syntax highlighting of different code files "out of the box" - Visual Basic included!

Download & install it, fire it up, and load up your VBA code. You should automatically see it beautifully coloured (if not, because the file extension is something other than .vb, go to Language -> VB or Language -> V -> VB).

If you need to change any of the colours, you can easily do so - just go to Settings -> Styler Configurator. From that menu, you can change the various highlighting and font options, to suit your needs - although the default usually suffices for most.

Then, go to Plugins -> NppExport. From there, you have three options you can consider:

  • Directly print from Notepad++
  • Copy all formats to clipboard
  • Export to RTF
  • Export to HTML

The first is self explanatory. The second one - "Copy all formats to clipboard" - will copy the entire file with the highlighted syntax to the clipboard. Once you click it, then open Microsoft Word or your other favourite document editor, and just hit paste! You should see the beautifully syntax-highlighted code. If something goes wrong, then you can try one of the other options (export to RTF/HTML), although I've never had a problem with the clipboard method.

like image 88
Breakthrough Avatar answered Sep 23 '22 18:09

Breakthrough