Hi all
I've the following Problem: Our VB 6.0 - Application uses the OLE
Container Control to use Word in embedded Mode from the Application.
With Word 2002 the Code works fine, but with Word 2003 we don't have
access to the OLE Containers Data to save the last changings of the
document.
Code Snipets:
'to activate Word in Embedded Mode - No Inplace Activation
Private Sub Command1_Click()
boolEnableSave = false
OLE1.HostName = "OLE Test"
OLE1.CreateEmbed ("C:\Test.doc")
OLE1.AutoActivate = vbOLEManual
'use vbOLEOpen not vbOLEShow, so Word is launched as separate
Application
'but control remains under the VB - Application
OLE1.DoVerb vbOLEOpen
end Sub
'to catch end of editing in Word
Private Sub OLE1_Updated(Code As Integer)
Select Case Code
Case vbOLEChanged
Case vbOLESaved
Case vbOLEClosed
boolEnableSave = true
Case vbOLERenamed
End Select
End Sub
'to save the Containers Data back to the File
Private Sub Command1_Click()
if boolEnableSave then
OLE1.object.saveas "C:/Test.doc"
OLE1.Close
OLE1.Delete
End Select
End Sub
Note:
With Word 2003, any access to the OLE1.object after having closed Word
(e.g. either by pressing Alt-F4 or using the menue 'close and return
to ...')
will cause a error:
'The object invoked has disconnected from its clients. / Nr:
-2147417848'
This happens also allready in the Eventroutine for OLE1
(OLE1_Updated)!
But how can I catch the lates changes, when the user quits Word???
I NEED HELP! Any Ideas?
Greetings
andreas
Andreas Schnegg - 30 Apr 2004 13:51 GMT
Hi - have found a workaround to the problem:
Since we cannot access the OLE1.object (=Word.Document) after having
left the application - we try to save the content before word is
closed. therefore you need to declare a variable by using withEvents:
Private WithEvents wrd As Word.Application
after having created the OLE-object by
OLE1.CreateEmbed ("C:\Test.doc")
you catch the reference to the Application object by
set wrd = OLE1.object.application
After that you will be able to catch the close-event of the document
before the application quits and you can save the embedded Doc's Data
to the Filesystem using saveas!
Private Sub wrd_DocumentBeforeClose_
(ByVal Doc As Word.Document, Cancel As Boolean)
Doc.saveas("C:\Test.doc")
end sub
This way you are no longer dependent on the poor colaboration
behaviour between the OLE Container Control and the different Versions
of Office
(Note: the behaviour of Office 2000 in the same test is diffrent
again!)
hope this helps someone
andreas
> Hi all
> I've the following Problem: Our VB 6.0 - Application uses the OLE
[quoted text clipped - 51 lines]
>
> andreas