当前位置:优学网  >  在线题库

使用excel vba计算word中的注释量失败

发表时间:2022-07-24 00:00:02 阅读:105

我想获得word文档中评论的数量.当word文档只有文本和注释时,我的代码可以工作.

但是,当我在包含表格的word文档上运行(excel vba)代码时,我得到运行时错误91"对象变量或未设置块变量".

我不知道是否需要这些信息:当word文档中有一个表时,那么表中也有对文本的注释...

如何更改为每个word文档运行的代码?

提前感谢您的帮助!

现在我的代码:

Dim appWord As Word.Application
Dim document As Word.Document

ThisWorkbook.Worksheets("Tabelle4").Activate

Set appWord = CreateObject("Word.Application")

' This word document just contains text and comments and with this document there is no runtime error 91
Set document = appWord.Documents.Open( _
ThisWorkbook.Path & "\Testfile_JustTextAndComments.docx")

' This word document contains tables, text and comments and with this document there arises a runtime error 91
'Set document = appWord.Documents.Open( _
'ThisWorkbook.Path & "\Testfile_TableTextAndComments.docx")

' Show the amount of comments in the word document
Range("A1") = document.Comments.Count ' when I click the debug-button of the runtime error 91 this line of code is marked (with Testfile_TableTextAndComments.docx)

document.Close wdDoNotSaveChanges
appWord.Quit
Set document = Nothing
Set appWord = Nothing
🎖️ 优质答案
相关问题