Word Automation. I can't Understand this Error (1 Viewer)

Pleasure

Registered User.
Local time
Today, 07:34
Joined
Jul 26, 2005
Messages
44
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 ((((
 

Attachments

  • Word Change.zip
    4.5 KB · Views: 191

Pleasure

Registered User.
Local time
Today, 07:34
Joined
Jul 26, 2005
Messages
44
I forgot to tell you that this code was working until I installed the beta Office 2007. But after uninstalling the office 2007 the problem seems to remain. Any suggestions ?
 

Users who are viewing this thread

Top Bottom