|
- Sub addCm(fn,newn)
- Set wdApp = CreateObject("word.application")
- On Error Resume Next
- Set myWDoc = wdApp.Documents.Open(Chr(34)&fn&Chr(34))
- wdApp.Visible = false
- wdApp.ScreenUpdating = False
- rows = myWDoc.Comments.Count
- If rows = 0 Then
- myWDoc.Close
- Exit Sub
- End If
- ReDim commentsArray(rows, 5)
- For i = 1 To rows
- commentsArray(i, 1) = myWDoc.Comments(i).Scope.Information(3) '页码
- commentsArray(i, 2) = myWDoc.Comments(i).Scope.Information(10) '行号
- commentsArray(i, 3) = myWDoc.Comments(i).Scope '批注引用内容
- commentsArray(i, 4) = myWDoc.Comments(i).Range '批注内容
- commentsArray(i, 5) = myWDoc.Comments(i).Author '作者
- Next
- myWDoc.Close
- Set myWDoc = Nothing
- Set myWDoc = wdApp.Documents.Open(Chr(34)&newn&Chr(34))
- myWDoc.Activate
- For i = 1 To rows
- wdApp.Selection.GoTo 1, 1, commentsArray(i, 1)
- wdApp.Selection.GoTo 3, 2, commentsArray(i, 2)-1
- wdApp.Selection.Find.ClearFormatting
- With wdApp.Selection.Find
- .Text = commentsArray(i, 3)
- .Replacement.Text = ""
- .Forward = True
- .Wrap = wdFindAsk
- .Wrap = wdFindContinue
- .Format = False
- .MatchCase = False
- .MatchWholeWord = False
- .MatchKashida = False
- .MatchDiacritics = False
- .MatchAlefHamza = False
- .MatchControl = False
- .MatchByte = True
- .MatchWildcards = False
- .MatchSoundsLike = False
- .MatchAllWordForms = False
- End With
- wdApp.Selection.Find.Execute
- Set myRange = wdApp.Selection.Range
- wdApp.Selection.Comments.Add myRange,commentsArray(i, 4)
- Next
- wdApp.ScreenUpdating = True
- myWDoc.Save
- myWDoc.Close
- wdApp.Quit
- End Sub
复制代码 本意:合并多个word文档的批注到一个word文档中,目前存在的问题是:
通过获取批注的页码和行号,在包含表格的页上获取的行号,再使用 goto 方法定位行时出错,他们从上往下数的行数不一致;导致定位不准;
commentsArray(i, 1) = myWDoc.Comments(i).Scope.Information(3) '页码
commentsArray(i, 2) = myWDoc.Comments(i).Scope.Information(10) '行号
请问怎样准确定位到批注位置,便于查找并合并批注;
详细代码和素材见附件!
|
|