Save embedded OLE object as a file

  • Thread starter Thread starter Kevin K. Sullivan
  • Start date Start date
K

Kevin K. Sullivan

Using A2k

I have a Word documents embedded in an OLE field in a table. I display them
using a Bound Object Frame in a Form. What code can I use to save a copy of
an embedded Word document to a file?

TIA,
e
Kevin
 
Hi Kevin,

The only remotely simple way I know is to use the bound object frame in
the (or a) form to launch the document in Word, and then automate Word
to save it to a file. Navigate to the record in question, then use the
objectframe's Verb and Action properties to launch the document. After
that it's ordinary Automation of the Word object model.
 
Thanks for your advice, John. I've gotten the following to work:
My form has bound object frame named bofTemplate
Command button code:
'''''''''''''''''''''''''''''
Private Sub cmdLaunch_Click()
'Launches an embedded Word document, saves a copy to a file, and closes Word

Dim oApp As Word.Application
Dim oDoc As Word.Document

'Open the object in its own application - MS Word in this case
Me.bofTemplate.Verb = acOLEVerbOpen
Me.bofTemplate.Action = acOLEActivate

'set a pointer to the application to allow automation -- kind of kludgy if
Word is already running
Set oApp = GetObject(, "Word.Application")
oApp.Visible = False

'set the document variable to the highest numbered Word doc - kludge!
Set oDoc = oApp.Documents(oApp.Documents.Count)

oDoc.SaveAs "C:\once embedded template.dot"

oDoc.Close False

oApp.Quit False

Set oDoc = Nothing

Set oApp = Nothing

End Sub
'''''''''''''''''''''''
I can see how problems could arrise if Word were already open with a bunch
of documents open. I can't come up with a more precise way of getting a
more precise handle to the application/document spawned by openning the
embedded document. Any how, this works for the time being. Thanks,

Kevin
 
Hi Kevin,

I think there probably is one, if you go into API calls. A simpler
alternative, on a reasonably specced computer, would just be to use

Set oApp = CreateObject("Word.Application")

to have your own hidden instance of Word with no other documents to
worry about.
 
Back
Top