Dear Developers.
I'm trying to implement a small VB6 program that performs a Find and Replace Action in a word document. The problem is that I'm getting this:
"runtime error 430 - Class does not support automation or does not support expected interface."
All references seems to be ok.
Please have a look at the attachment. I also include a small word document where we are going to change everything with [XXXXXX] to hello friend. Place the document at c:\
The code is :
Public APWORD As Word.Application
Public Doc As Document
Private Sub Command1_Click()
Set APWORD = New Word.Application
APWORD.Visible = False
Set Doc = APWORD.Documents.Open("c:\document.doc")
Doc.Select
On Error GoTo ErrorOcurred
'make the changes to the body of the document
With APWORD.Selection.Find
.Text = "[" & Trim("XXXXX") & "]"
.Replacement.Text = Trim("Hello Friend")
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
APWORD.Selection.Find.Execute Replace:=wdReplaceAll
'make the changes to the header - footer of the document
Dim HeaderFooter As Word.Range
For Each HeaderFooter In APWORD.ActiveDocument.StoryRanges
With HeaderFooter.Find
.Text = "[" & Trim("XXXXX") & "]"
.Replacement.Text = Trim("Hello Friend")
.Wrap = wdFindContinue
.Format = False
.Forward = True
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
HeaderFooter.Find.Execute Replace:=wdReplaceAll
Next
'save the document
Doc.SaveAs ("c:\documentnew.doc")
Doc.Close False
ErrorOcurred:
Success:
End Sub
Please help me. I'm desperate ((((
I'm trying to implement a small VB6 program that performs a Find and Replace Action in a word document. The problem is that I'm getting this:
"runtime error 430 - Class does not support automation or does not support expected interface."
All references seems to be ok.
Please have a look at the attachment. I also include a small word document where we are going to change everything with [XXXXXX] to hello friend. Place the document at c:\
The code is :
Public APWORD As Word.Application
Public Doc As Document
Private Sub Command1_Click()
Set APWORD = New Word.Application
APWORD.Visible = False
Set Doc = APWORD.Documents.Open("c:\document.doc")
Doc.Select
On Error GoTo ErrorOcurred
'make the changes to the body of the document
With APWORD.Selection.Find
.Text = "[" & Trim("XXXXX") & "]"
.Replacement.Text = Trim("Hello Friend")
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
APWORD.Selection.Find.Execute Replace:=wdReplaceAll
'make the changes to the header - footer of the document
Dim HeaderFooter As Word.Range
For Each HeaderFooter In APWORD.ActiveDocument.StoryRanges
With HeaderFooter.Find
.Text = "[" & Trim("XXXXX") & "]"
.Replacement.Text = Trim("Hello Friend")
.Wrap = wdFindContinue
.Format = False
.Forward = True
.MatchCase = True
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
HeaderFooter.Find.Execute Replace:=wdReplaceAll
Next
'save the document
Doc.SaveAs ("c:\documentnew.doc")
Doc.Close False
ErrorOcurred:
Success:
End Sub
Please help me. I'm desperate ((((