Angus
Fri Dec 05 05:37:23 CST 2003
Unfortunately the article didn't really help
Here is my code
Private Sub cmdMCA_Click()
Dim objWord As Word.Application
Dim objWordDoc As Word.Document '''''''''''''''''****
Dim docspath As String
Dim StrToWord As String
StrToWord = "Angus Comber 1 The Avenue Berks"
Dim sDear As String
sDear = "Angus"
On Error Resume Next 'WordStart
Set objWord = GetObject(, "Word.Application")
If Err.Number = 429 Then
Set objWord = New Word.Application '
CreateObject("Word.Application")
End If
If objWord Is Nothing Then
MsgBox "objWord is nothing"
Exit Sub
End If
objWord.Visible = True
docspath = "c:\program files\ioffice\ltemplat\letter.dot"
Set objWordDoc = objWord.Documents.Add(docspath, False)
' Sometime get a valid objWord object but problem creating document based on
template.
' So still need to check a valid objWordDoc created
If objWordDoc Is Nothing Then
MsgBox "Unable to create Word Document object based on template: " &
docspath & " Unable to proceed with Word creation", vbCritical, "Word Error"
' LogError Err.Number, "Unable to create objWordDoc object. 'Set
objWordDoc = objWord.Documents.Add(docspath, Fales)'", "Letter in
frmContacts"
Exit Sub
End If
Dim bRet As Boolean
bRet = objWordDoc.Range.Find.Execute("<Address>", , , , , , , , , StrToWord,
True)
MsgBox "Return value from Execute Address: " & bRet
bRet = objWordDoc.Range.Find.Execute("<Dear>", False, False, , , , , , ,
sDear, True)
MsgBox "Return value from Execute Dear: " & bRet
''''''''' MIGHT WORK -> '''''''
objWordDoc.Range.WholeStory ' select all text
objWord.StatusBar = "objWordDoc.Range.WholeStory"
bRet = objWordDoc.Range.Find.Execute("<Address>", False, False, False,
False, False, True, Word.wdFindContinue, False, "Abba", Word.wdReplaceAll)
MsgBox "Return value from Execute Address: " & bRet
Dim myrange As Word.Range
Set myrange = ActiveDocument.Content
myrange.Find.Execute FindText:="Add", ReplaceWith:="hello",
Replace:=wdReplaceAll
End Sub
All msgbox's return false.
The machine was installed by Dell - apparently their default Office install.
If I look in Add/Remove Programs on the PC I see Microsoft Office XP
Professional (Size 21.53MB)
I can create a normal macro in Word doing similar thing and it works.
The VB program loads the Word doc OK - so automation is working - just not
the Find.Execute line!
I am desperate to get this fixed asap.
Any help would be much appreciated.
Angus
"Rick Stebbins" <AutomateOffice@yahoo.com> wrote in message
news:d47201c3bac1$c98b9b50$a601280a@phx.gbl...
> Hi Angus,
>
> If your string variable contains text, probably the find
> is not succeeding. So, try looking at the
>
http://www.mvps.org/word/FAQs/MacrosVBA/FlushFR.htm
> article. Also, you should specify either the wdReplaceOne
> or wdReplaceAll constant for the Replace parameter instead
> of True.
>
> Rick
>
> >-----Original Message-----
> >I have written a VB6 program which generates a Word
> letter based on a
> >template and then runs the command below:
> >
> >objWord.Selection.Find.Execute "<Address>", , , , , , , ,
> , strToWord, True
> >
> >where objWord is of type Word.Application
> >
> >This works fine on Office 97, 2000 and on my Word 2002 on
> XP test PC.
> >
> >It is funny because most of the VBA code works - ie the
> code to load a Word
> >document based on the correct template works fine. The
> problem is that the
> ><Address> text is NOT replaced with the contents of the
> strToWord variable.
> >
> >Anyone any ideas why?
> >
> >Angus Comber
> >angus@NOSPAMiteloffice.com
> ><Remove NOSPAM to email me>
> >
> >
> >.
> >