删除Wordfile的所有注释
Delete all comments of Wordfile
所以我试图根据 VBA-Excel 文件的代码删除 Word 文件中的所有评论。
我试过使用
'Dim ObjWord as Word.Application
ObjWord.ActiveDocument.DeleteAllComments
并打电话
Sub RemoveAllComments(Doc As Document)
Dim n As Long
Dim oComments As Comments
Set oComments = Doc.Comments
For n = oComments.Count To 1 Step -1
oComments(n).Delete
Next
Set oComments = Nothing
End Sub
但第一个给了我 运行-time 'error 4605 command not available',第二个代码段抛出“错误 438 对象不支持此 属性 或方法”。
还有其他方法吗?
编辑 1:
Dim ObjWord As Word.Application
Set ObjWord = LoadWord()
ObjWord.Visible = True
在函数中,它调用 LoadWord():
Function LoadWord() As Word.Application
Set LoadWord = GetObject(, "Word.Application")
If MsgBox("Word's already in use klick ok to dismiss all changes", vbOKCancel) = vbCancel Then
Set LoadWord = Nothing
End If
Exit Function
End Function
错误 4605:
ObjWord.ActiveDocument.DeleteAllComments
表示 ActiveDocument(如果有)不包含注释。由于您没有发布任何与如何实例化 ActiveDocument(或 Doc,在您的第二个子程序中)相关的代码,或者您是否已经确定相关文档甚至包含任何评论,因此不可能在这方面提供进一步的建议.
此外,这:
Sub RemoveAllComments(Doc As Document)
将无效。至少需要是:
Sub RemoveAllComments(Doc As ObjWord.Document)
对于第一个例子,没有比以下更复杂的方法可以补救这种情况:
On Error Resume Next
ObjWord.ActiveDocument.DeleteAllComments
On Error Goto 0
所以我试图根据 VBA-Excel 文件的代码删除 Word 文件中的所有评论。
我试过使用
'Dim ObjWord as Word.Application
ObjWord.ActiveDocument.DeleteAllComments
并打电话
Sub RemoveAllComments(Doc As Document)
Dim n As Long
Dim oComments As Comments
Set oComments = Doc.Comments
For n = oComments.Count To 1 Step -1
oComments(n).Delete
Next
Set oComments = Nothing
End Sub
但第一个给了我 运行-time 'error 4605 command not available',第二个代码段抛出“错误 438 对象不支持此 属性 或方法”。
还有其他方法吗?
编辑 1:
Dim ObjWord As Word.Application
Set ObjWord = LoadWord()
ObjWord.Visible = True
在函数中,它调用 LoadWord():
Function LoadWord() As Word.Application
Set LoadWord = GetObject(, "Word.Application")
If MsgBox("Word's already in use klick ok to dismiss all changes", vbOKCancel) = vbCancel Then
Set LoadWord = Nothing
End If
Exit Function
End Function
错误 4605:
ObjWord.ActiveDocument.DeleteAllComments
表示 ActiveDocument(如果有)不包含注释。由于您没有发布任何与如何实例化 ActiveDocument(或 Doc,在您的第二个子程序中)相关的代码,或者您是否已经确定相关文档甚至包含任何评论,因此不可能在这方面提供进一步的建议.
此外,这:
Sub RemoveAllComments(Doc As Document)
将无效。至少需要是:
Sub RemoveAllComments(Doc As ObjWord.Document)
对于第一个例子,没有比以下更复杂的方法可以补救这种情况:
On Error Resume Next
ObjWord.ActiveDocument.DeleteAllComments
On Error Goto 0