Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Work with only one Instance of Word
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00658782
Message ID:
00659160
Views:
27
Barbara,

Thank You,

So I would prefer to use:
oDoc = GetObject(lcDocument, "Word.Application")
Right?

But if that's not possible, I should do something like
IF VARTYPE(oWord) = "U" .OR. VARTYPE(oWord) = "X"
   oWord = CREATEOBJECT("Word.Application")
ENDIF
oDoc = GetObject(lcDocument)
oWord.Visible = .T.
That looks like it would work, but it appears to still create two instances of WINWORD and the second one doesn't open my second document.

ARRGGH

>I think your confusion here comes from getting an object reference to Word itself versus getting an object reference to the document within Word. GetObject is what you want to make sure there's only one instance of Word open, but if you only pass it the document name, what you get back is an object reference to the document. That's why you can't set Visible to .T. You need a reference to Word to set Word's Visible property.
>
>The second syntax, where you call GetObject with both the document name and "Word.Application", should work in getting you an object reference to Word. I just tried this, and it worked for me, however, the document was not visible in Word when I set the Visible property to .T. Checking the Documents.Count property showed 0. I'm not sure exactly how to solve your problem right now. Maybe someone else will jump in with the answer to that. If not, I can probably figure it out when I get more time.
>
>>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 Rogers
Epic Solutions
www.epicsolutions.net
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform