我正在尝试使用 vba 将文字样式应用于一行文本,以便它出现在目录中。不过,我无法将样式包含在有问题的行中,由于某种原因,整个文档都在采用这种样式。
With Selection
.TypeText Text:=headername ' This is defined previously,
.HomeKey Unit:=wdLine, Extend:=wdMove ' This is to move the cursor to the start of the line
.Expand wdLine ' This is to select the whole line
.Style = "Heading 2" ' this is to define the style of the selected text
.EndKey Unit:=wdLine, Extend:=wdMove ' This is to unhighlight the text
.InsertBreak Type:=wdLineBreak ' This is to create a line break
End With
但由于某种原因,整个文档都采用了“标题 2”作为它的风格。我尝试了无数其他方法来做到这一点,但没有运气,
有谁知道这样做的更好方法,或者看看我哪里出错了?
谢谢