VBA Word 更改 table 单元格中特定单词的字体大小
VBA Word change font size of specific words in a table cell
来自 Excel 我正在编辑 Microsoft Word 文档。我的 Word 文档中有一个 table,其中第 4 列包含一个数字,然后是字母 wk。
示例:
+------+------+------+-------+
| Col1 | Col2 | Col3 | Col4 |
+------+------+------+-------+
| test | 2 | 123 | 1 wk |
| test | 2 | 123 | 13 wk |
| test | 2 | 123 | 10 wk |
+------+------+------+-------+
我正在尝试更改字母 wk 的字体大小。我想我可以通过选择来做到这一点,然后替换字母,但它在 VBA via Excel 中绝对不起作用。我怎样才能做到这一点?
我当前的代码:
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 列,则您不需要 select 该列。例如:
With WDApp.ActiveDocument.Tables(1).Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "wk"
.Replacement.Text = "^&"
.Replacement.Font.Size = 9
.Execute Replace:=wdReplaceAll
End With
来自 Excel 我正在编辑 Microsoft Word 文档。我的 Word 文档中有一个 table,其中第 4 列包含一个数字,然后是字母 wk。
示例:
+------+------+------+-------+
| Col1 | Col2 | Col3 | Col4 |
+------+------+------+-------+
| test | 2 | 123 | 1 wk |
| test | 2 | 123 | 13 wk |
| test | 2 | 123 | 10 wk |
+------+------+------+-------+
我正在尝试更改字母 wk 的字体大小。我想我可以通过选择来做到这一点,然后替换字母,但它在 VBA via Excel 中绝对不起作用。我怎样才能做到这一点?
我当前的代码:
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 列,则您不需要 select 该列。例如:
With WDApp.ActiveDocument.Tables(1).Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "wk"
.Replacement.Text = "^&"
.Replacement.Font.Size = 9
.Execute Replace:=wdReplaceAll
End With