Text colour using Word object in VB - TechRepublic
General discussion
May 12, 2006 at 06:39 AM
jaxbauer

Text colour using Word object in VB

by jaxbauer . Updated 20 years, 1 month ago

How can I change the colour of text I am writing to a Word document I have created in VB using the Word object. The code sample I am using is shown below:

Public Sub WriteText(ByVal SomeText As String)

Dim objRange As Word.Range

Set objRange = objDocument.Bookmarks.Item(“\endofdoc”).Range

objRange.Font.Name = “Arial”
objRange.Font.Bold = False
objRange.Font.ColorIndex = wdRed
‘objRange.Font.Color = wdColorRed
objRange.ParagraphFormat.SpaceAfter = 1
objRange.InsertAfter SomeText
objRange.InsertParagraphAfter

Set objRange = Nothing

End Sub

When I run my program, the font type does change to Arial & the text is written in bold but the colour stays at the default of black. What am I doing wrong?

This discussion is locked

All Comments