[英]VBA Word change font size of specific words in a table cell
從Excel,我正在編輯Microsoft Word文檔。 我的Word文檔中有一個表,其中第4列包含一個數字,然后是字母wk 。
例:
+------+------+------+-------+
| Col1 | Col2 | Col3 | Col4 |
+------+------+------+-------+
| test | 2 | 123 | 1 wk |
| test | 2 | 123 | 13 wk |
| test | 2 | 123 | 10 wk |
+------+------+------+-------+
我正在嘗試更改字母wk的字體大小。 我以為我可以選擇,然后替換字母,但這絕對不能通過Excel在VBA中使用。 我該如何實現?
我當前的代碼:
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
這未經測試並且可以在移動設備上使用,所以請在這里與我聯系。
當前,您不更改“替換”文本的文本大小,因此應更新為.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
嘗試:
Tbl.Columns(4).Select
With WDApp.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "wk"
.Replacement.Text = "^&"
.Replacement.Font.Size = 9
.Execute Replace:=wdReplaceAll
End With
注意:如果只有包含“ wk”的單元格在第4列中,則無需選擇該列。 例如:
With WDApp.ActiveDocument.Tables(1).Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "wk"
.Replacement.Text = "^&"
.Replacement.Font.Size = 9
.Execute Replace:=wdReplaceAll
End With
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.