How do you copy VBA code into a Word document and retain the VBA editor color scheme?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
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.