B
Brian Wissert
Hi everyone,
I am working with Access 2000, VBA, OLE automation, and Word 2000
I have a table in access that contains an ID and an embedded word document.
I am trying to activate the document and search for a keyword. When I find
this word I want to highlight it in yellow wherever it appears in the
document. I keep crashing.
Here is my code:
Private Sub btnActivate_Click()
Dim ctl As Control
Dim strSearch As String
Dim appWD As Word.Application
Dim rngTemp As Range
Dim myDoc As Document
Forms![CEO Resume Search]!txtKeyword.SetFocus
strSearch = txtKeyword.Text
'Open the Word document for editing
'This works, the word app opens with the embedded document showing.
Set ctl = Me!OLEBoundResumeView
With ctl
' Set Locked property to False.
..Locked = False
' Set Verb property to activate for editing.
..Verb = acOLEVerbOpen
' Activate object.
..Action = acOLEActivate
End With
Set appWD = GetObject(, "Word.Application")
appWD.Options.DefaultHighlightColorIndex = wdYellow
'This works, the word app opens and the highlight function is set to yellow.
Set myDoc = Documents(1)
With myDoc.Content.Find
'This is my problem area
..ClearFormatting
..Text = strSearch
..Replacement.ClearFormatting
..Replacement.Text = strSearch
..Replacement.Highlight = True
..Execute FindText:=strSearch, ReplaceWith:=strSearch, Format:=True,
Replace:=wdReplaceAll
End With
End Sub
When I run the code, I get an error, -2147220995 - Object is not connected
to server. Then access crashes. Oops.
It correctly sets the highlighting color index to yellow within the opened
Word application, so I know that I am communicating with Word.
I think I am probably referencing the object incorrectly. It crashes when I
start to use the Find code.
Any help would be greatly appreciated.
Thank You
I am working with Access 2000, VBA, OLE automation, and Word 2000
I have a table in access that contains an ID and an embedded word document.
I am trying to activate the document and search for a keyword. When I find
this word I want to highlight it in yellow wherever it appears in the
document. I keep crashing.
Here is my code:
Private Sub btnActivate_Click()
Dim ctl As Control
Dim strSearch As String
Dim appWD As Word.Application
Dim rngTemp As Range
Dim myDoc As Document
Forms![CEO Resume Search]!txtKeyword.SetFocus
strSearch = txtKeyword.Text
'Open the Word document for editing
'This works, the word app opens with the embedded document showing.
Set ctl = Me!OLEBoundResumeView
With ctl
' Set Locked property to False.
..Locked = False
' Set Verb property to activate for editing.
..Verb = acOLEVerbOpen
' Activate object.
..Action = acOLEActivate
End With
Set appWD = GetObject(, "Word.Application")
appWD.Options.DefaultHighlightColorIndex = wdYellow
'This works, the word app opens and the highlight function is set to yellow.
Set myDoc = Documents(1)
With myDoc.Content.Find
'This is my problem area
..ClearFormatting
..Text = strSearch
..Replacement.ClearFormatting
..Replacement.Text = strSearch
..Replacement.Highlight = True
..Execute FindText:=strSearch, ReplaceWith:=strSearch, Format:=True,
Replace:=wdReplaceAll
End With
End Sub
When I run the code, I get an error, -2147220995 - Object is not connected
to server. Then access crashes. Oops.
It correctly sets the highlighting color index to yellow within the opened
Word application, so I know that I am communicating with Word.
I think I am probably referencing the object incorrectly. It crashes when I
start to use the Find code.
Any help would be greatly appreciated.
Thank You