I'm trying to apply a word style to a line of text using vba, so that it will appear in the table of contents. I am having trouble keeping the style contained to the line in question though, for some reason the whole document is picking up the style.
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 …
Run Code Online (Sandbox Code Playgroud)