Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Detecting Excel being open
Message
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01162978
Message ID:
01162989
Views:
16
>>Sorry to keep asking Q's friends. Maybe one day soon I'll be an automation wizard buit at the moment I'm on the steep bit of the curve.
>>
>>It's a good idea to close the Excel app after creating and manipulating a w/b or sheet., otherwise Excel.exe remains as a process but only shows up in the Task Manager, and if you try to create another incidence you can get a dispatch error over the contention (something like that anyway).
>>
>>You create the w/s and open it for the user to inspect
>>
>>But there are 2 scenarios:
>>
>>a) the user looks at it and closes, either the workbook (leaving the Excel shell), or Excel proper
>>b) they look at it and go back to the VFP app window, without closing
>>
>>In case a), attempting to close Excel, from the VFP code causes an error.
>>In case b), you can get the above mentioned dispatch error if try to do another export in the same VFP session.
>>
>>So 'twould be nice to ascertain whether or not an incidence of Excel is running before deciding what to do.
>>
>>How to do this please?
>>
>>'ppreciate it
>>
>>Terry
>
>That is why when I use automation after I show Word (in my case) I going in a loop untill Word is closed. Something like:
>
>
>....
>
>oExcel.Visible = .t.
>DECLARE Sleep IN WIN32API INTEGER
>DO WHILE TYPE(oExcel.Name]) == [C] AND;
>         NOT ISNULL(oExcel)
>   Sleep(300) && Put it in sleep mode so other application can work :-)
>ENDDO
>oExcel = NULL
>RELEASE oExcel
>
Thanks BB. On the ball as usual! :-)

So, in the code after:
loExcel .Visible = .T.

... where control is passed to the user, in Excel, I have:

Wait Window "Done"
.ActiveWorkBook.Close()
.Quit()
loExcel = NULL
RELEASE loExcel

so I wouldn't need the

.ActiveWorkBook.Close()
.Quit()

cos the user is forced to do that before being allowed to continue with VFP?

UPDATE:

I've done the above and now it goes into an unbreakable do loop, whether I've closed Excel before returning to the VFP app window, or I've left Excel open and returned. I have

loExcel.Visible = .T.
Wait Window "Done"
* For Now> loExcel.ActiveWorkBook.Close()
DO WHILE TYPE( [loExcel.Name]) == [C] AND;
NOT ISNULL( loExcel)
Sleep(300) && Put it in sleep mode so other application can work :-)
ENDDO
* For Now> loExcel.Quit()
loExcel = NULL
RELEASE loExcel
- Whoever said that women are the weaker sex never tried to wrest the bedclothes off one in the middle of the night
- Worry is the interest you pay, in advance, for a loan that you may never need to take out.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform