目次に表示されるように、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」を採用しています。私はこれを行うために無数の他の方法を試しましたが、運が悪く、
誰かがこれを行うためのより良い方法を知っていますか、または私が間違っている場所を見ていますか?
ありがとう