Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Work with only one Instance of Word
Message
From
27/05/2002 10:16:44
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00658782
Message ID:
00661677
Views:
25
>I have a command button labeled "Edit Letter" to enable my users to edit letters used within my app. I am trying to properly launch only a single instance of Word. Currently in the click event, I have:
>
>LOCAL lcDocument
>lcDocument = FULLPATH("letters\pcb"+ This.Parent.cboLetterType.Value+".doc")
>oWord = CreateObject("Word.Application")
>oDoc = oWord.Documents.Open(lcDocument)
>oWord.Visible = .T.
>
>
>I understand that with this code, if the user clicks the button a second time without closing Word, a second instance is created thereby consuming memory. Now according to VFP Documentation AND Tamar Ganor's book MS Office Automation With VFP, I should be able to use the GetObject() function to either create an instance of Word if needed or if Word is already started, simply open the document. I have tried the following with the same assignment as above to lcDocument:
>
>oDoc = GetObject(lcDocument)
>oDoc.Visible = .T.
>
>The second line returns an "OLE error code... Unknown Name."
>
>I've tried
>
>oDoc = GetObject(lcDocument, "Word.Application")
>oDoc.Visible = .T.
>
>The first line returns an "OLE error code....No such interface supported."
>
>I'm just not understanding the GetObject() function. Isn't this what I want to use prevent the second launch of MS Word?
>
>Thank you very much

Elgin,

oWord = GetObject(, "Word.Application")
oWord.Documnts.Open(lcDoc)

Basically either creates a new instance or gets one existing if any. BUT never do it IMO. When you need one use createobject() or if you're keen about you want one only at least do it like :

if isnull(oApp.oWord)
oApp.oWord = createobject("Word.Application")
endif

My 0.2 cents.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform