Automation Error - Word/Find

S

Steve Barnett

I have an app that uses Word for report writing. On one machine I am getting
an "automation error - out of memory" whenever I use the Find mechanism to
locate some text for replacement and am looking for some ideas as to what it
might be.

I stripped down the app to the absolute minimum I need to test word
automation (reproduced below) and find that I consistently get this error on
the Find.Execute statement.

The machine having the problem is Windows/XP Pro SP1, Office/XP SP2. It has
lots of free disk space and plenty of memory. The temp folder isn't
particularly full of files. The app is written in VB6 SP5. This code works
fine on several dozen other machines (including another machine with the
above spec).

Anyone help?
Steve

The code I have been using for testing is:

Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document

Public Sub TestWord()
Dim sFileName As String
Dim nChange As Integer
Dim sChangeFrom As String
Dim sChangeTo As String
Dim oRange As Word.Range
Dim bFound As Boolean

'*** Create instance of word and make it visible so I can
'*** see what's going on.
Set oWordApp = CreateObject("Word.application")
oWordApp.Visible = True

'*** Load the document we want to change
sFileName = App.Path & "\mytest.doc"
Set oWordDoc = oWordApp.Documents.Open(sFileName, False, False, False)

'*** Save with a new name so we don't overwrite the original
sFileName = App.Path & "\MySaved.doc"
oWordDoc.SaveAs sFileName

'*** Find and change the stuff we want changed
For nChange = 1 To 10
sChangeFrom = "%n" & Trim$(Str$(nChange)) & "%"
sChangeTo = "Field" & Trim$(Str$(nChange))
bFound = True

'*** Looks for %n1% and replaces with Field1 (same for 2 thru 10)
Do While bFound
Set oRange = oWordDoc.Range
With oRange.Find
.ClearFormatting '************************This works

bFound = .Execute(sChangeFrom, True, False, False, False)
'****** Fails
If bFound Then
oRange.Text = sChangeTo
End If
End With
Loop
Next

'*** Save the changes
oWordDoc.Save

'*** Close Word
oWordApp.Quit
set oWordApp = nothing
End Sub
 
S

Steve Barnett

I did look at this (and have forwarded to the clients technical services)
but thought it was a little far fetched that the Excel 5 type library would
get re-registered. Still, it looks good, if far fetched.

Thanks
Steve


alpine said:
You might want to have a look at the following....

BUG: Automation Client Receives Error Calling Word Find Object
[Q292744]
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q292744


HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'(e-mail address removed) Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas


I have an app that uses Word for report writing. On one machine I am getting
an "automation error - out of memory" whenever I use the Find mechanism to
locate some text for replacement and am looking for some ideas as to what it
might be.

I stripped down the app to the absolute minimum I need to test word
automation (reproduced below) and find that I consistently get this error on
the Find.Execute statement.

The machine having the problem is Windows/XP Pro SP1, Office/XP SP2. It has
lots of free disk space and plenty of memory. The temp folder isn't
particularly full of files. The app is written in VB6 SP5. This code works
fine on several dozen other machines (including another machine with the
above spec).

Anyone help?
Steve

The code I have been using for testing is:

Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document

Public Sub TestWord()
Dim sFileName As String
Dim nChange As Integer
Dim sChangeFrom As String
Dim sChangeTo As String
Dim oRange As Word.Range
Dim bFound As Boolean

'*** Create instance of word and make it visible so I can
'*** see what's going on.
Set oWordApp = CreateObject("Word.application")
oWordApp.Visible = True

'*** Load the document we want to change
sFileName = App.Path & "\mytest.doc"
Set oWordDoc = oWordApp.Documents.Open(sFileName, False, False, False)

'*** Save with a new name so we don't overwrite the original
sFileName = App.Path & "\MySaved.doc"
oWordDoc.SaveAs sFileName

'*** Find and change the stuff we want changed
For nChange = 1 To 10
sChangeFrom = "%n" & Trim$(Str$(nChange)) & "%"
sChangeTo = "Field" & Trim$(Str$(nChange))
bFound = True

'*** Looks for %n1% and replaces with Field1 (same for 2 thru 10)
Do While bFound
Set oRange = oWordDoc.Range
With oRange.Find
.ClearFormatting '************************This works

bFound = .Execute(sChangeFrom, True, False, False, False)
'****** Fails
If bFound Then
oRange.Text = sChangeTo
End If
End With
Loop
Next

'*** Save the changes
oWordDoc.Save

'*** Close Word
oWordApp.Quit
set oWordApp = nothing
End Sub
 
A

alpine

I see this fairly often with Word/Excel 2K and XP.

HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'(e-mail address removed) Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas


I did look at this (and have forwarded to the clients technical services)
but thought it was a little far fetched that the Excel 5 type library would
get re-registered. Still, it looks good, if far fetched.

Thanks
Steve


alpine said:
You might want to have a look at the following....

BUG: Automation Client Receives Error Calling Word Find Object
[Q292744]
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q292744


HTH,
Bryan
____________________________________________________________
New Vision Software "When the going gets weird,"
Bryan Stafford "the weird turn pro."
alpine_don'(e-mail address removed) Hunter S. Thompson -
Microsoft MVP-Visual Basic Fear and Loathing in LasVegas


I have an app that uses Word for report writing. On one machine I am getting
an "automation error - out of memory" whenever I use the Find mechanism to
locate some text for replacement and am looking for some ideas as to what it
might be.

I stripped down the app to the absolute minimum I need to test word
automation (reproduced below) and find that I consistently get this error on
the Find.Execute statement.

The machine having the problem is Windows/XP Pro SP1, Office/XP SP2. It has
lots of free disk space and plenty of memory. The temp folder isn't
particularly full of files. The app is written in VB6 SP5. This code works
fine on several dozen other machines (including another machine with the
above spec).

Anyone help?
Steve

The code I have been using for testing is:

Dim oWordApp As Word.Application
Dim oWordDoc As Word.Document

Public Sub TestWord()
Dim sFileName As String
Dim nChange As Integer
Dim sChangeFrom As String
Dim sChangeTo As String
Dim oRange As Word.Range
Dim bFound As Boolean

'*** Create instance of word and make it visible so I can
'*** see what's going on.
Set oWordApp = CreateObject("Word.application")
oWordApp.Visible = True

'*** Load the document we want to change
sFileName = App.Path & "\mytest.doc"
Set oWordDoc = oWordApp.Documents.Open(sFileName, False, False, False)

'*** Save with a new name so we don't overwrite the original
sFileName = App.Path & "\MySaved.doc"
oWordDoc.SaveAs sFileName

'*** Find and change the stuff we want changed
For nChange = 1 To 10
sChangeFrom = "%n" & Trim$(Str$(nChange)) & "%"
sChangeTo = "Field" & Trim$(Str$(nChange))
bFound = True

'*** Looks for %n1% and replaces with Field1 (same for 2 thru 10)
Do While bFound
Set oRange = oWordDoc.Range
With oRange.Find
.ClearFormatting '************************This works

bFound = .Execute(sChangeFrom, True, False, False, False)
'****** Fails
If bFound Then
oRange.Text = sChangeTo
End If
End With
Loop
Next

'*** Save the changes
oWordDoc.Save

'*** Close Word
oWordApp.Quit
set oWordApp = nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top