提问人:smolo 提问时间:11/9/2023 最后编辑:smolo 更新时间:11/9/2023 访问量:31
使用VBA添加邮件合并字段并设置特定的字体设置
Add mail merge field with VBA and set specific font settings
问:
此VBA的目的是在文档中查找文本“Something”,在其后插入一个空格,添加一个名为“address”的邮件合并字段,然后使用特定的字体设置设置插入的字段的格式。添加部分工作正常,但文本没有格式化。
Sub AddMailMergeField()
Dim rng As Range
' Set the range after "Something" text
Set rng = ActiveDocument.Range
rng.Find.Text = "Something"
rng.Find.Execute
' Insert a space
rng.Collapse Direction:=wdCollapseEnd
rng.InsertAfter " "
' Insert the mail merge field "address"
ActiveDocument.MailMerge.Fields.Add rng, "address"
' Format the inserted field
With rng
.Font.Name = "Arial"
.Font.Size = 30
.Font.ColorIndex = wdRed
End With
End Sub
答:
1赞
Black cat
11/9/2023
#1
使用以下命令修改代码:
取而代之的是,将这个With rng
rng.Expand wdWord
rng.Select
With Selection
评论