我需要将带有下划线/删除线的Microsoft Word中的跟踪更改转换为实际文本。我在使用交叉引用处理跟踪的更改时遇到了困难。
例如,如果交叉引用更新,从第5段到第6段,它将显示为" 6 5 " [6有下划线,但stackoverflow没有格式化选项]我想仅保留5作为原始文本,但保留6作为交叉引用字段。
如果交叉引用已经/替换/使用新的交叉引用,我已经得到了下面的宏,这将执行我想要的操作。但是,如果仅更新交叉引用,它仍然无法正常工作。任何帮助将不胜感激:
Sub TypeAndStrike()
Dim chgAdd As Word.Revision
Dim Colour
Colour = RGB(255, 0, 0) ' Set the color to change the changes to.
'PD Colors: Black (0, 0, 0), Red (255, 0, 0), Green (0, 255, 0), Blue (0, 0, 255), Brown (165, 42, 42)
Dim SkipNext As Integer
' disable tracked revisions.
If ActiveDocument.Revisions.Count = 0 Then
MsgBox "There are no revisions in this document", vbOKOnly
Else
ActiveDocument.TrackRevisions = False
For Each chgAdd In ActiveDocument.Revisions
If chgAdd.Type = wdRevisionDelete Then ' It's a deletion, so make it strike through and then reject the change (so the text isn't lost).
SkipNext = 0
chgAdd.Range.Select ' move insertion point
chgAdd.Range.Font.StrikeThrough = True
chgAdd.Range.Font.Color = Colour
For Each testRange In Selection.Range.Fields ' Replace cross-refs with >text
testRange.Select
If Selection.Range = chgAdd.Range Then
SkipNext = 1
End If
Selection.TypeText Text:=Selection.Text
Next
If SkipNext = 0 Then
chgAdd.Range.Select
chgAdd.Reject
End If
ElseIf chgAdd.Type = wdRevisionInsert Then ' It's an addition, so underline it.
chgAdd.Range.Font.Underline = wdUnderlineSingle
chgAdd.Range.Font.Color = Colour
chgAdd.Accept
Else
chgAdd.Range.Select ' move insertion point
End If
Next chgAdd
End If
End Sub
答案 0 :(得分:0)
我还没有使用Revisions工作,所以我的建议可能有缺点,但是,我可能会对Field.Result做一些事情。
交叉引用是一个REF字段,在封面下 - 按Alt + F9,您可以在字段代码视图上切换以查看它。
当代码查询ActiveDocument.Fields([index]).Result
时,返回一个RANGE对象(为任何Field.Result返回一个Range)。 Result.Text
以纯文本形式返回可见结果 - 在您的示例65中。
其本身并没有用。但是,如果将它与Result.Revisions.Count
组合在一起,您可以找出在该字段中存储了多少修订(如果有的话)。使用您的示例,Count
返回两个,您知道第一个(左)是更改,第二个(右)是原始。这应该让你弄清楚应该是什么价值。然后,您可以删除字段(Field.Unlink
)并将所需结果写入文档?