如何漂亮地打印VBA代码?
如何将 VBA 代码复制到 Word 文档中并保留 VBA 编辑器配色方案?
How do you copy VBA code into a Word document and retain the VBA editor color scheme?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以使用 Notepad++ 通过三种方式完成此操作。如您所知,Notepad++ 是记事本的更高级版本,它“开箱即用”支持不同代码文件的语法突出显示 - 包括 Visual Basic!
下载&安装它,启动它,然后加载您的 VBA 代码。您应该会自动看到它漂亮的颜色(如果没有,因为文件扩展名不是
.vb
,请转到语言 -> VB 或语言 -> V -> VB)。如果您需要更改任何颜色,您可以轻松地做到这一点 - 只需转到“设置”->“造型器配置器。从该菜单中,您可以更改各种突出显示和字体选项,以满足您的需求 - 尽管默认值通常足以满足大多数人的需求。
然后,转到插件 -> NppExport。从那里,您可以考虑三个选项:
第一个是不言自明的。第二个 - “将所有格式复制到剪贴板” - 将整个文件与突出显示的语法复制到剪贴板。单击它后,打开 Microsoft Word 或您喜欢的其他文档编辑器,然后点击粘贴!您应该看到语法突出显示的精美代码。如果出现问题,那么您可以尝试其他选项之一(导出为 RTF/HTML),尽管我从未遇到过剪贴板方法的问题。
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.
cnet 上有两个程序可供下载,可以免费试用。如果您没有尝试过,请参阅以下链接:
There are two programs on cnet downloads, which are free to try. In case you did not try them, here are the links:
智能压头可能是您正在寻找的东西?您将结果加载到 Notepad++ 中,将语言设置为 VB 并另存为 .rtf/.doc (或打印到文件,我一时记不清了)。
Smart Indenter could be what you're looking for? You'd load the result into Notepad++, set language to VB and save as .rtf/.doc (or print to file, can't remember off the top of my head).
对于更现代的方法,Sublime Text 用户可以从 Package Control 安装 ExportHTML。这样做的额外好处是能够包含行号并更改代码颜色。
HTML 文件可以直接在 Word 中打开。
For a more modern approach, Sublime Text users can install ExportHTML from Package Control. This has the added benefit of being able to include the line numbers, and changing the code coloration.
HTML files can be opened directly within Word.
Highlight 支持多种操作系统和 150 多种语言,包括 Visual Basic,尽管我不确定关于VBA。
Highlight supports a wide range of Operating Systems and 150+ languages including Visual Basic, although I'm not sure about VBA.
我推荐这个: planetB
它与 Internet Explorer 配合良好(不起作用对我来说是 Firefox,不确定 Chrome)。
而且它是在线的,因此无需安装任何东西(公司/大学电脑的情况)
I would recommend this one: planetB
It works well with Internet Explorer (didn't work wit Firefox for me, not sure abt Chrome).
Plus it's online, so no need to install anything (the case of Company/University PC's)
以下内容适用于 Visual Studio Code:
The following works with Visual Studio Code: