将立即窗口的内容写入文本文件
我正在编写一个宏,它会遍历文档并尝试按样式解析它。现在,指定样式的任何内容都会复制到直接窗口中。有没有办法进一步自动化宏,将文本从即时窗口移动到 txt 文件中?否则,任何使用宏的人都无法看到文本,除非他们打开 VBA,对吗?
I'm writing a macro which goes through a document and tries to parse it by Style. Right now, anything in the designated style is copied onto the immediate window. Is there a way to automate the macro further to move the text from the immediate window into a txt file? Otherwise, anyone using the macro would not be able to see the text unless they opened up VBA, correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是我的建议:同时写入即时窗口和文件。下面的例子。
为什么要让信息首先在立即窗口中传输,然后才从那里写入文件?这听起来很反常且毫无用处!
请注意,最后一段代码需要设置引用:工具>参考文献>> Microsoft Scripting Runtime 处的复选标记。
Here's my suggestion: write to the immediate window AND to a file at the same time. Examples below.
Why make the information first transit in the immediate window, and only then write it to a file from there? That just sounds perversely and uselessly difficult!
Note that this last bit of code requires a reference to be set: Tools > References > checkmark at Microsoft Scripting Runtime.
将此代码放入即时窗口并按 Enter 键以将列表写入 C# 中的 JSON 文本。
Put this code to immediate window and hit enter to write the List to JSON text in C#.
我建议使用一些基于最佳实践的日志框架,例如VBA 日志记录,支持并行配置的文件日志记录或控制台等
示例用法(例如在某些
Foo.bas
module):产生类似的结果(在控制台和 vba_logging.log 文件中):
其中日志配置文件如下所示:
I would recommend to use some best-practices-based logging framework like VBA Logging, which supports file logging or console configurably in parallel etc.
example usage (e.g. in some
Foo.bas
module):resulting in something like (both in console and
vba_logging.log
file):where the log config file looks like this: