tut*_*utu 0 excel vba ms-word excel-2010
我正在从 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 |
+------+------+------+-------+
Run Code Online (Sandbox Code Playgroud)
我正在尝试更改字母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
Run Code Online (Sandbox Code Playgroud)
这是未经测试的移动设备,所以请耐心等待。
目前您没有更改“替换”文本的文本大小,因此您应该更新为 .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
Run Code Online (Sandbox Code Playgroud)