访问 MSWord ActiveDocument 时遇到问题
当我尝试以编程方式访问 Word 对象模型时,收到一条错误消息,指出没有活动文档。 这似乎是因为我使用 Word 自动化将文档加载为不可见,并且我必须使其保持不可见。
我该如何对开放宏进行编码,使其在这种情况下不执行任何操作?
If Not ActiveDocument is Nothing then
不起作用。
Private Sub Document_Open()
If (ActiveDocument.SaveFormat = wdFormatRTF) Then
'Do some stuff
End If
End Sub
When I try to programmatically access a Word object model, I get an error saying no document is active. This appears to be because I am loading the document as not visible using Word automation, and I have to keep it invisible.
How would I code the open macro so that it does nothing in this case?
If Not ActiveDocument is Nothing Then
didn't work.
Private Sub Document_Open()
If (ActiveDocument.SaveFormat = wdFormatRTF) Then
'Do some stuff
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以记住您打开的文档(一些示意性代码),而不是使用 ActiveDocument:
Instead of using ActiveDocument you could remember the document that you open (some schematic code):