我是否可以使用数组值使用VBA来设置Word文档中字段的文本?
Do While .Execute
Selection.MoveDown Unit:=wdLine, count:=1
Selection.Paragraphs.Indent
For I = 0 To mergeFields.GetUpperBound(0)
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, PreserveFormatting:=False
Selection.TypeText Text:="MERGEFIELD M_1"
Selection.MoveRight Unit:=wdCharacter, count:=2
Selection.TypeParagraph
Next 代替"MERGEFIELD M_1",我想从一个名为"mergeFields“的数组中填充该文本,该数组的名称类似于字符串。之所以如此,是因为该数组是在一个单独的函数中动态设置的,因此我可能需要创建5个新字段或最多20个新字段。
所以我的想法如下:
Selection.TypeText Text:= mergeField(I)
Selection.MoveRight Unit:=wdCharacter, count:=2
Selection.TypeParagraph这样的事有可能吗?
发布于 2015-03-11 14:49:47
算了吧,经过一点调整我就能让它开始工作了。以下是其他人的最终代码:
Do While .Execute
Selection.MoveDown Unit:=wdLine, count:=1
Selection.Paragraphs.Indent
For Each fieldName In mergeFields
If fieldName <> "" Then
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, PreserveFormatting:=False
Selection.TypeText Text:=mergeFields(I)
Selection.MoveRight Unit:=wdCharacter, count:=2
Selection.TypeParagraph
I = I + 1
End If
Next
Loophttps://stackoverflow.com/questions/28989190
复制相似问题