VBA Word将格式化文本转换为曲目更改

时间:2018-04-17 13:53:24

标签: vba word-vba

我需要将错误跟踪更改的文档还原为实际的跟踪更改。

我已经编写了这段代码,但它减慢了应用程序和Word挂起的速度。还有更好的选择吗?

Sub FormattingToTC()
    'Main procedure for the transformation of track changes
    Dim rev As Revision
    Dim sect As Section
    Dim selAccepted As Selection
    Dim selDel As Selection
    Dim storyRange As Range
    Dim strFullName As String, strName As String, strOldFullName As String
    Dim strPath As String
    Dim OriginalDoc As Document

    Application.DisplayAlerts = wdAlertsNone
    ActiveDocument.TrackFormatting = False
    ActiveDocument.TrackRevisions = False


    Selection.Find.ClearFormatting
    Selection.Find.Font.StrikeThrough = True  'Find all strikethrough text
    With Selection.Find
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
    End With

    Do While Selection.Find.Execute = True  'All matches are deleted with tracked changes active
        ActiveDocument.TrackRevisions = True
        Selection.Delete
    Loop
    Selection.Find.ClearFormatting
    Selection.Find.Highlight = True  'Find all hihglighted text
    With Selection.Find
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True

    End With

    Do While Selection.Find.Execute = True  'All matches are deleted with tracked changes active
        ActiveDocument.TrackRevisions = False
        Selection.Copy
        Selection.Delete
        ActiveDocument.TrackRevisions = True
        Selection.paste
    Loop
    Application.DisplayAlerts = wdAlertsAll
end sub

只会删除部分。另一种方法是避免这种循环吗?例如,使用find和replace?

0 个答案:

没有答案