Reputation: 695
From Excel I am editing a Microsoft Word document. I have a table in my Word document where column 4 consists of a number and then the letters wk after it.
Example:
+------+------+------+-------+
| Col1 | Col2 | Col3 | Col4 |
+------+------+------+-------+
| test | 2 | 123 | 1 wk |
| test | 2 | 123 | 13 wk |
| test | 2 | 123 | 10 wk |
+------+------+------+-------+
I am trying to change the font size of the letters wk. I figured I could do this with selection and then replace the letters, but it's definitely not working in VBA via Excel. How can I achieve this?
My current code:
Tbl.Columns(4).Select
WDApp.Selection.Find.ClearFormatting
With WDApp.Selection.Find
'.ClearFormatting
.Text = "wk"
.Replacement.Text = "wk"
.Font.Size = 9
End With
WDApp.Selection.Find.Execute Replace:=wdReplaceAll
Upvotes: 0
Views: 2393
Reputation: 3257
This is untested and on mobile, so bear with me here.
Currently you’re not changing the text size of the “replacement” text, so you should update to .Replacement.Font.Size = 9
With WDApp.ActiveDocument.Content.Find
.ClearFormatting
.ClearAllFuzzyOptions
.Text = "wk"
With .Replacement
.Text = "wk" 'this line might be unnecessary
.Font.Size = 9
End With
.Execute Format:=True, Replace:=wdReplaceAll
End With
Upvotes: 5
Reputation: 13515
Try:
Tbl.Columns(4).Select
With WDApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "wk"
.Replacement.Text = "^&"
.Replacement.Font.Size = 9
.Execute Replace:=wdReplaceAll
End With
Note: If the only cells containing 'wk' are in column 4, you don't need to select the column. For example:
With WDApp.ActiveDocument.Tables(1).Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "wk"
.Replacement.Text = "^&"
.Replacement.Font.Size = 9
.Execute Replace:=wdReplaceAll
End With
Upvotes: 2