Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word font not changing colour 1

Status
Not open for further replies.

Domino2

Technical User
Jun 8, 2008
475
GB
I have a procedure that finds a word in word documents. It finds the word, and changes the font size, but the found word remains black. Any ideas why, thanks

'Create an instance of MS Word
Set WD = CreateObject(Class:="Word.Application")
'WD.Visible = True
'
' 'Open the Document
WD.Documents.Open Filename:=LWordDoc, ReadOnly:=True

Me.List152.SetFocus
Me.List152.ListIndex = 0

For TY = 0 To Me.List152.ListCount - 1
Me.List152.ListIndex = TY

With WD.Selection.Find
.ClearFormatting
.Text = "When"
.Replacement.ClearFormatting
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

End With

Do While WD.Selection.Find.Execute
ccny = ccny + 1

If WD.Selection.Find.Found Then

With WD.Selection.Font
.Color = wdColorRed
.Name = "Arial"
.Size = 18
.Bold = True
.Italic = True
.Underline = wdUnderlineAll 'None
.UnderlineColor = wdColorAutomatic
.Strikethrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = True
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With

End If


Loop


Next TY


DoEvents
WD.ActiveDocument.Saved = True

WD.Visible = True

Set rst = Nothing
Set db = Nothing
Me.Command153.Enabled = True
End Sub
 
Guess that you have reference to Microsoft Word x.0 Object library. Otherwise wdColorRed is assumed to be 0 (=wdColorBlack).
Do you save the document somewhere? WD.ActiveDocument.Saved = True only resets information used to ask user for saving changed document.


combo
 
Hey Combo, you hit the nail on the head, I'd lost my Word references. Thanks very much!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top