vba - 在 AutoNew 子中附加模板的问题
问题描述
我在 VBA MS Word 中编写了一个宏来自动在新文档中附加模板:
Sub AutoNew()
ActiveDocument.AttachedTemplate = <Path To Template>
ActiveDocument.UpdateStylesOnOpen = True
End Sub
但是,此宏无法正常工作。它附加模板,模板工作中的宏,但它不更新样式。只有 Normal 模板中的样式可用。你能告诉我我能做什么吗?提前致谢
解决方案
颠倒命令的顺序。您需要告诉文档从模板更新样式,然后附加它。
我会推荐:
Sub AutoNew()
Let ActiveDocument.UpdateStylesOnOpen = True
Let ActiveDocument.AttachedTemplate = <Path To Template>
Let ActiveDocument.UpdateStylesOnOpen = False ' Once styles are imported, turn off this attribute
End Sub
- 请注意关闭该设置的结尾。这是保持活动状态的糟糕设置,它与文档保持一致。
像 Timothy Rylatt 一样,我想知道您为什么不简单地根据相关模板开始文档。然后样式已经存在。
推荐阅读
- python - Python中数据集的第一次分析-多标准
- c# - 在图片框中查看保存为字符串的图像
- ruby-on-rails - 在 Rails 中跟踪 sidekiq 作业
- c# - C# WPF 应用程序 - 在运行时修改数据表的问题 - System.ArgumentOutOfRangeException
- google-cloud-platform - Apache Beam 中的窗口函数
- python - Dask - map_partition
- spreadsheet - 有没有办法在 Google 表单中生成和显示唯一 ID?
- spring-boot - 尝试多对一实体映射时出现未知列错误
- bison - “轻松”转变/减少冲突
- python-3.x - 读取具有动态值的 sql 文件