×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Convert underline/strikethrough to Track Changes

Convert underline/strikethrough to Track Changes

Convert underline/strikethrough to Track Changes

(OP)
Dear Friends,

I have found several helpful snippets of code on here to convert MSWord Track Change revisions to underline/strikethrough revisions as character formatting.

I have the reverse problem, however: I have a document where insertions are shown as underline, and deletions are shown as strikethrough with character formatting, and I want to work with it as a change-tracked document, for example with with my revisions on top, or to accept/reject certain revisions. So, I need to transform the character formatting underline to Track Change insertion, and the character formatting strikethrough to Track Change deletion.

Trying to do this via Find/Replace is having me tearing my hair out.

Would anyone have a clue as to how to do this with a bit of VBA?

All the best,

Mark

RE: Convert underline/strikethrough to Track Changes

Start by turning on macro recorder.

Then do what you are doing.

RE: Convert underline/strikethrough to Track Changes

Handling deletions is relatively easy, assuming I've understood your problem properly. Insertions are harder ...

CODE

    Dim OldTrack As Boolean
    
    OldTrack = ActiveDocument.TrackRevisions
    
    If Not OldTrack Then ActiveDocument.TrackRevisions = True

    With Selection.Find
        .ClearFormatting
        .Font.StrikeThrough = True
        .Text = ""
        .Replacement.Text = ""
        .Replacement.ClearFormatting
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    ActiveDocument.TrackRevisions = OldTrack 

RE: Convert underline/strikethrough to Track Changes

Try:

CODE

Sub Demo()
Application.ScreenUpdating = False
Dim StrTxt As String
With ActiveDocument
  With .Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = ""
      .Replacement.Text = ""
      .Forward = True
      .Format = True
      .Font.StrikeThrough = True
      .Wrap = wdFindStop
      .Execute
    End With
    Do While .Find.Found
      .End = .Words.Last.End
      StrTxt = .Text
      ActiveDocument.TrackRevisions = False
      .Text = StrTxt
      ActiveDocument.TrackRevisions = True
      .Delete
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
  With .Range
    With .Find
      .ClearFormatting
      .Replacement.ClearFormatting
      .Text = ""
      .Replacement.Text = ""
      .Forward = True
      .Format = True
      .Font.Underline = True
      .Wrap = wdFindStop
      .Execute
    End With
    Do While .Find.Found
      If .Words.First.Previous = " " Then
        .Start = .Start - 1
      Else
        .End = .Words.Last.End
      End If
      StrTxt = .Text
      ActiveDocument.TrackRevisions = False
      .Text = vbNullString
      ActiveDocument.TrackRevisions = True
      .Text = StrTxt
      .Collapse wdCollapseEnd
      .Find.Execute
    Loop
  End With
  .TrackRevisions = False
End With
Application.ScreenUpdating = True
End Sub 

Cheers
Paul Edstein
[MS MVP - Word]

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close