访问 MSWord ActiveDocument 时遇到问题

发布于 2024-07-10 15:01:40 字数 355 浏览 7 评论 0原文

当我尝试以编程方式访问 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-07-17 15:01:40

您可以记住您打开的文档(一些示意性代码),而不是使用 ActiveDocument:

dim word as new Word.Application
dim doc as Word.Document

doc = word.Documents.Open(fileName)
MsgBox doc.FullName

Instead of using ActiveDocument you could remember the document that you open (some schematic code):

dim word as new Word.Application
dim doc as Word.Document

doc = word.Documents.Open(fileName)
MsgBox doc.FullName
戈亓 2024-07-17 15:01:40
If Documents.Count > 0 Then
If Documents.Count > 0 Then
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文