Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / COM / April 2004



Tip: Looking for answers? Try searching our database.

HELP! OLE Container Control does not work with Word 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andreas Schnegg - 20 Apr 2004 10:27 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.