Word07 VBA读取修订信息Revisions出错,运行时错误'5852',要求的对象不可用
Word07 VBA读取修订信息Revisions出错,运行时错误'5852',要求的对象不可用
代码如下:
Public Sub ExecuteCompare(KeyDocPath As String, CompareDocDirPath As String)
Dim keyDoc As Document, comDoc As Document, newDoc As Document
'打开原始文档
Set keyDoc = Documents.Open(FileName:=KeyDocPath, Visible:=False)
Set comDoc = Documents.Open(FileName:=CompareDocDirPath, Visible:=False)
Set newDoc = Application.CompareDocuments(keyDoc, comDoc)
keyDoc.Close
comDoc.Close
WriteResultToTextFile newDoc.Revisions, Replace(CompareDocDirPath, ".docx", ".txt")
End Sub
'将不同之处记录到一个与doc文档同名的txt文件中
Private Sub WriteResultToTextFile(ResultRevisions As Revisions, FileName As String)
Dim iCount As Integer, rev As Revision
Dim FSO As New FileSystemObject, ts As TextStream
Set ts = FSO.CreateTextFile(FileName)
ts.WriteLine ("共" & CStr(ResultRevisions.Count) & "处修订:")
ts.WriteBlankLines 1
iCount = 1
For Each rev In ResultRevisions
ts.WriteLine iCount & TypeToDescription(rev.Type)
ts.Write rev.Range
ts.WriteBlankLines 2
iCount = iCount + 1
Next
ts.Close
Set ts = Nothing
End Sub
'返回用户更改的类型对应说明
Private Function TypeToDescription(revType As WdRevisionType) As String
Dim retStr As String
Select Case revType
Case WdRevisionType.wdNoRevision
retStr = "无修订"
Case WdRevisionType.wdRevisionConflict
retStr = "将修订标记为冲突"
Case WdRevisionType.wdRevisionDelete
retStr = "删除"
Case WdRevisionType.wdRevisionDisplayField
retStr = "域显示方式已更改"
Case WdRevisionType.wdRevisionInsert
retStr = "插入"
Case WdRevisionType.wdRevisionParagraphNumber
retStr = "段落编号已更改"
Case WdRevisionType.wdRevisionParagraphProperty
retStr = "段落属性已更改"
Case WdRevisionType.wdRevisionProperty
retStr = "属性已更改"
Case WdRevisionType.wdRevisionReconcile
retStr = "将修订标记为已解决的冲突"
Case WdRevisionType.wdRevisionReplace
retStr = "已替换"
Case WdRevisionType.wdRevisionSectionProperty
retStr = "节属性已更改"
Case WdRevisionType.wdRevisionStyle
retStr = "样式已更改"
Case WdRevisionType.wdRevisionStyleDefinition
retStr = "样式定义已更改"
Case WdRevisionType.wdRevisionTableProperty
retStr = "表格属性已更改"
Case WdRevisionType.wdRevisionCellDeletion
retStr = "表格单元格已删除"
Case WdRevisionType.wdRevisionCellInsertion
retStr = "表格单元格已插入"
Case WdRevisionType.wdRevisionCellMerge
retStr = "表格单元格已合并"
Case WdRevisionType.wdRevisionMovedFrom
retStr = "移动内容的起点"
Case WdRevisionType.wdRevisionMovedTo
retStr = "移动内容的终点"
Case Else
retStr = "未知错误"
End Select
TypeToDescription = retStr
End Function
求熟悉VBA的帮忙解决一下。
[解决办法]
调试下,看对象是否为空。
[解决办法]
rev为异常!
[解决办法]
有没有什么办法能够直接读审阅窗格的内容???