Try setting your range, outputting the text and then applying the formatting. If I move the formatting commands in front of the InsertText method it does not work, but the below code produced red underlined text.
Place an OLE control on a form and in the click event enter:
myOleObject.CreateEmbed "", "Word.Document.8"
Set appWRD = myOleObject.object.Application
Set myRange = appWRD.ActiveDocument.GoTo(What:=wdGoToLine, Which:=wdGoToLast)
myRange.Select
myRange.InsertAfter "Some text" & vbCrLf
myRange.Underline = wdUnderlineSingle
myRange.Font.ColorIndex = wdRed
Set appWRD = Nothing
Now, the problem I am having is trying to apply two differen types of formatting on two different lines within a newly created documet. I want to underline the text inserted into the first line, start a new paragraph and turn the underline off.
pstrText = "Some text"
Set appWRD = oleAddendums.object.Application
' insert some underlined text
appWRD.ActiveDocument.Range(Start:=0, End:=0).InsertBefore Text:=pstrText & vbCrLf
appWRD.ActiveDocument.Range.Underline = wdUnderlineSingle
appWRD.ActiveDocument.Range.Collapse (wdCollapseEnd)
' add new paragraph (carriage return/line feed) to end of inserted text and turn off underline
appWRD.ActiveDocument.Range(Start:=Len(pstrText) + 1, End:=Len(pstrText) + 1).InsertAfter " " & vbCrLf
appWRD.ActiveDocument.Range.Select
appWRD.ActiveDocument.Range.Underline = wdUnderlineNone
' move cursor to end of document
Set myRange = appWRD.ActiveDocument.GoTo(What:=wdGoToLine, Which:=wdGoToLast)
myRange.Select
Set appWRD = Nothing
If I just insert the underlined text and move to the end of the document, underlining remains on for whatever other text is inserted via code or entered into Word by the user. Turning underline off in the second part of the code also removes the underline from the first line. I can't seem to separate the formatting for the two parts.