Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Automation - avoiding 2 copies of Word
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00748221
Message ID:
00748244
Views:
20
I made my first attempt at starting word from VFP7, works fine except if the code [following] is started twice from the button on the form, I get two copies of Word starting, not a second document window within Word.

This is because CREATEOBJECT() always creates a new instance of Word. What you need to do is use GETOBJECT() to grab a reference to an existing instance of Word. Unfortunately, the GETOBJECT() syntax can crash with error 1426 if there is no existing reference. This code should help get you started:
*** Use GetObject to grab a reference to an existing
*** instance of the server or create one if there is none
llNeedInstance = .F.
lcOldOnError = ON( 'ERROR' )
ON ERROR llNeedInstance = .T.
oWord = GETOBJECT( , 'Word.Application' )
IF EMPTY( lcOldOnError )
  ON ERROR
ELSE
  ON ERROR &lcOldOnError
ENDIF
IF llNeedInstance
  oWord = CREATEOBJECT( 'Word.Application' )
ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform