jason456
08-09-2014, 06:47 PM
I'm new to VB and mail merging, so my terminology may be a little off. Thanks for understanding.
So, I have a word doc that I use to make sale signs. I'm using mail merge to pull the product brands, sizes, sale prices, savings, etc from excel. There is a mix of font sizes and styles all throughout the file.There are four signs (records) per page. I'm using a macro to format the sale prices, because I want the "cents" portion of the price to be superscript and a smaller font size than the "dollar" portion. I'm using the macro, because the sale price is a single cell in excel and gets pulled into word with uniform formatting. The way that I got my find/replace working is to have the sale price italicized and have italics be my gating condition for the search.
The problem now is that I have a second, similar file with slightly different requirements, and I'd like to handle with this same macro. I want the find/replace to act on all italicized text. If that text is not bolded, then set the cents to a certain font size. If the text IS bolded, then the cents should be set to a different size.
At the end of the macro, I remove italics and bold from the sale price.
Here's what I have, along with some pseudocode at the branching point. This has to be a simple operation, but I can't get it to work. Can you help?
Sub Format_4up_Sale_Price()'
' Format_4up_Sale_Price Macro
'
'
Dim newsize As Integer
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ".[0-9][0-9]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
'====== Code in question ========
'pseudo code:
' If Selection is bold
' newsize = 90
' Else
' newsize = 82
' End If
'end pseudocode
With Selection.Find.Replacement.Font
.Size = newsize
.Superscript = True
.Subscript = False
End With
'====== End question ========
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Italic = False
Selection.Find.Replacement.Font.Bold = False
With Selection.Find
.Text = "*"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub
So, I have a word doc that I use to make sale signs. I'm using mail merge to pull the product brands, sizes, sale prices, savings, etc from excel. There is a mix of font sizes and styles all throughout the file.There are four signs (records) per page. I'm using a macro to format the sale prices, because I want the "cents" portion of the price to be superscript and a smaller font size than the "dollar" portion. I'm using the macro, because the sale price is a single cell in excel and gets pulled into word with uniform formatting. The way that I got my find/replace working is to have the sale price italicized and have italics be my gating condition for the search.
The problem now is that I have a second, similar file with slightly different requirements, and I'd like to handle with this same macro. I want the find/replace to act on all italicized text. If that text is not bolded, then set the cents to a certain font size. If the text IS bolded, then the cents should be set to a different size.
At the end of the macro, I remove italics and bold from the sale price.
Here's what I have, along with some pseudocode at the branching point. This has to be a simple operation, but I can't get it to work. Can you help?
Sub Format_4up_Sale_Price()'
' Format_4up_Sale_Price Macro
'
'
Dim newsize As Integer
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ".[0-9][0-9]"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
'====== Code in question ========
'pseudo code:
' If Selection is bold
' newsize = 90
' Else
' newsize = 82
' End If
'end pseudocode
With Selection.Find.Replacement.Font
.Size = newsize
.Superscript = True
.Subscript = False
End With
'====== End question ========
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "."
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
Selection.Find.Font.Italic = True
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Font.Italic = False
Selection.Find.Replacement.Font.Bold = False
With Selection.Find
.Text = "*"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub