I've created a word doc with bookmarks that I use to populate from my tables. I need to be able to search for certain words after the merge has occured and then make those words Italic. I've tried the following code:
Dim objWord As Word.Application
Set objWord = CreateObject ("Word.Application"
With objWord
.visible = True
.Documents.Open ("C:\test.doc"
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
'Italics Code
.Selection.Find.Replacement.Font.Italic = True
With Selection.Find
.Text = "italic"
.Replacement.Text = "Found"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
End With
This code doesn't work though...any ideas what I'm doing wrong?
Bill
Dim objWord As Word.Application
Set objWord = CreateObject ("Word.Application"
With objWord
.visible = True
.Documents.Open ("C:\test.doc"
.Selection.Find.ClearFormatting
.Selection.Find.Replacement.ClearFormatting
'Italics Code
.Selection.Find.Replacement.Font.Italic = True
With Selection.Find
.Text = "italic"
.Replacement.Text = "Found"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
End With
This code doesn't work though...any ideas what I'm doing wrong?
Bill