Word Automation problem within PPT VBA

J

John Svendsen

Hi All,

I have a problem that is plaguing me. I need to constantly modify many
embedded Word objects in several PPT files. To do so I've put together a PPT
VBA code that does this, BUT if I have another instance of word running
(which many times I need to have) the code fails at the set command in the
code with the following error:

Run-time error '-2147220995 (800401fd)':
Method 'Object' of object 'OLEFormat' failed

I've done research on this (e.g.,
http://support.microsoft.com/default.aspx?scid=kb;en-us;189618) but no luck
if fixing this SET problem.

Can someone give me an idea of what to do?

Thanks so much, JS


Sub EmbeddedWord_Replace_All_Ask()
Dim oSlide As Slide
Dim oShape As Shape
Dim oDoc As Word.Document
Dim wdApp As Object
Dim FindText, ReplaceText As String
FindText = InputBox("Enter text to be found (to be replaced)")
ReplaceText = InputBox("Enter replacement text")
Set wdApp = CreateObject("Word.Application")
For Each oSlide In ActivePresentation.Slides
With oSlide
For Each oShape In .Shapes
If oShape.Type = msoEmbeddedOLEObject Then
If oShape.OLEFormat.ProgID = "Word.Document.8" Then
'======================================================
Set wdDoc = oShape.OLEFormat.Object '<<<=== CODE FAILS HERE
'======================================================
wdDoc.Select
With wdApp.Selection.Find
.Text = FindText
.ClearFormatting
.Replacement.Text = ReplaceText
.Replacement.ClearFormatting
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.Execute Replace:=wdReplaceAll
End With
wdDoc.Save
wdApp.ActiveDocument.Close wdSaveChanges = False
End If
End If
Next oShape
End With
Next oSlide
wdApp.Quit
End Sub
 
T

TC

I don't see wdDoc defined anywhere.

Are you /certain/ that the object returned by oShape.OLEFormat.Object,
can actually be used as if it was an open document, as you are doing?
Has that part of the code, ever worked at all?

HTH,
TC
 

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