Thread: [Solved] Need Help with Below Code
View Single Post
 
Old 03-30-2014, 09:05 AM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,341
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

Well, apart from the fact you deleted an existing expression in that macro, you added a space to the start of the new Find expression, omitted a new Replace expression, which means the preceding character would be deleted and a paragraph inserted in its place and, by putting it after the code that applies the 'Strong' Style, would turn the replaced output bold. Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .Text = "([!1-9])[0]{1,}([0-9]{1,})"
    .Replacement.Text = "\1\2"
    .Execute Replace:=wdReplaceAll
  End With
End With
Application.ScreenUpdating = True
End Sub
or, to integrate it into yesterday's macro:
Code:
Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  .InsertBefore " "
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchWildcards = True
    .Text = "([!1-9])[0]{1,}([0-9]{1,})"
    .Replacement.Text = "\1\2"
    .Execute Replace:=wdReplaceAll
    .Text = ".([0-9]{1,3}.)"
    .Replacement.Text = ". \1"
    .Execute Replace:=wdReplaceAll
    .Text = " ([a-e].)"
    .Replacement.Text = "^p\1"
    .Execute Replace:=wdReplaceAll
    .Replacement.Style = "Strong"
    .Text = " ([0-9]{1,3}.)"
    .Execute Replace:=wdReplaceAll
  End With
  .Characters.First.Delete
End With
Application.ScreenUpdating = True
End Sub
PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote