J
Jason L
Hey, I have a few (but lengthy) wildcard search for vba related questions.
First question, what is missing from this macro that is causing an error
that says something like the following, "...contains a group number which is
out of range"?
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[0-9]{1,}.[^32^s^t]@"
.Replacement.Text = "\1^+"
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=ReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("List Number 2")
Second question. Right now the above macro gets all unformatted number
paragraphs (1. text, 2. text, etc) and reformats them using a list number
template. There are times when the unformatted lists contain a space before
the number. Right now the macro isn't picking these up instances up. What
kind of modifications do I need to make to pick up these instances as well?
Final question. The text in this document contains sentences like the
following: Total Electrical Cost: $1,000,000.00. All of the text in this
document is merged from another source, so all formatting is lost. There are
several variations on this line. For example, some variations contain the
word "work" instead of "cost." Other times there are several other words
between Total and Cost. Also, there are times when the text is all caps, and
other times when the text is not. There are also times when the original
client forgets to insert a colon after "cost" or "work." Basically, I need
the macro to find any of these variations, format the text bold, align it
flush right, capitalize all text, and, if possible, add a colon before the
numberical amount. I've had some help on this before, but the client keeps
coming up with new variations on this paragraph, but they still have the same
expectations - automate the process.
Here is the code I have thus far (I know I shouldn't use asterisks, but I
was at a loss):
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = "Total*^13"
.Replacement.Text = "^&"
.Replacement.Font.Bold = True
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Total*Cost*^13"
With .ParagraphFormat
.Alignment = wdAlignParagraphJustify
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Replacement.Text = "^&"
With .Replacement
With .ParagraphFormat
.Alignment = wdAlignParagraphRight
End With
End With
.Execute Replace:=wdReplaceAll
TIA,
Jason
First question, what is missing from this macro that is causing an error
that says something like the following, "...contains a group number which is
out of range"?
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "[0-9]{1,}.[^32^s^t]@"
.Replacement.Text = "\1^+"
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=ReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Style = ActiveDocument.Styles("List Number 2")
Second question. Right now the above macro gets all unformatted number
paragraphs (1. text, 2. text, etc) and reformats them using a list number
template. There are times when the unformatted lists contain a space before
the number. Right now the macro isn't picking these up instances up. What
kind of modifications do I need to make to pick up these instances as well?
Final question. The text in this document contains sentences like the
following: Total Electrical Cost: $1,000,000.00. All of the text in this
document is merged from another source, so all formatting is lost. There are
several variations on this line. For example, some variations contain the
word "work" instead of "cost." Other times there are several other words
between Total and Cost. Also, there are times when the text is all caps, and
other times when the text is not. There are also times when the original
client forgets to insert a colon after "cost" or "work." Basically, I need
the macro to find any of these variations, format the text bold, align it
flush right, capitalize all text, and, if possible, add a colon before the
numberical amount. I've had some help on this before, but the client keeps
coming up with new variations on this paragraph, but they still have the same
expectations - automate the process.
Here is the code I have thus far (I know I shouldn't use asterisks, but I
was at a loss):
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = "Total*^13"
.Replacement.Text = "^&"
.Replacement.Font.Bold = True
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "Total*Cost*^13"
With .ParagraphFormat
.Alignment = wdAlignParagraphJustify
End With
.Forward = True
.Wrap = wdFindContinue
.Format = True
.Replacement.Text = "^&"
With .Replacement
With .ParagraphFormat
.Alignment = wdAlignParagraphRight
End With
End With
.Execute Replace:=wdReplaceAll
TIA,
Jason