【问题标题】:Trouble accessing MSWord ActiveDocument无法访问 MSWord ActiveDocument
【发布时间】:2010-09-27 05:16:11
【问题描述】:

当我尝试以编程方式访问 Word 对象模型时,我收到一条错误消息,提示没有文档处于活动状态。这似乎是因为我正在使用 Word 自动化加载不可见的文档,我必须让它保持不可见。

在这种情况下,我将如何对打开的宏进行编码以使其不执行任何操作?

If Not ActiveDocument is Nothing Then

没用。

Private Sub Document_Open()

   If (ActiveDocument.SaveFormat = wdFormatRTF) Then
      'Do some stuff
   End If

End Sub

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

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

    dim word as new Word.Application
    dim doc as Word.Document
    
    doc = word.Documents.Open(fileName)
    MsgBox doc.FullName
    

    【讨论】:

      【解决方案2】:
      If Documents.Count > 0 Then
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-09
        • 2021-01-04
        • 2019-12-16
        相关资源
        最近更新 更多