View Single Post
 
Old 12-10-2012, 11:44 PM
macropod's Avatar
macropod macropod is online now Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The following macro adds a series of tags (bold = <b></b>, italic = <i></i> & underlined = <u></u> - you can change that) to the bold, italic & underlined text in a document, and removes the bold, italic & underlined formatting at the same time.

Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = True
    .Text = ""
    .Font.Bold = True
    .Replacement.Text = "<b>^&</b>"
    .Replacement.Font.Bold = False
    .Execute Replace:=wdReplaceAll
    .ClearFormatting
    .Font.Italic = True
    .Replacement.Text = "<i>^&</i>"
    .Replacement.Font.Italic = False
    .Execute Replace:=wdReplaceAll
    .ClearFormatting
    .Font.Underline = True
    .Replacement.Text = "<u>^&</u>"
    .Replacement.Font.Underline = False
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
If you comment-out the three '.Replacement.Font' lines ending in 'False', the formatting will be retained.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote