BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

some Excel automation questions

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation
View previous topic :: View next topic  
Author Message
Erwin Kalvelagen
Guest





PostPosted: Tue Dec 16, 2003 1:03 am    Post subject: some Excel automation questions Reply with quote





Hi:


I am using Excel to let the user select a range. It works almost
perfectly. I have a little stay-on-top window that interogates the
olevariant object about 5 times a second and if the user is
happy (s)he can press ok, so that I can transfer the selected
range to another part of the program. I have two remaining
issues:

1. If the user selects a named range from my own little delphi
window, Excel looses focus. Afterwards I want Excel to get
the focus back. How can I get from the Excel application object
the hWnd of Excel so that I can call SetForeGroundWindow(hWnd)?
Currently I use FindWindow(nil,'Microsoft Excel') to find it but
that is not foolproof.

2. How can I detect that the user closes Excel? In that case
I want to close my Excel application object, and close my little
window.

Thanks, Erwin


----------------------------------------------------------------
Erwin Kalvelagen
GAMS Development Corp., http://www.gams.com
[email]erwin (AT) gams (DOT) com[/email], http://www.gams.com/~erwin
----------------------------------------------------------------



Back to top
Deborah Pate (TeamB)
Guest





PostPosted: Tue Dec 16, 2003 4:32 pm    Post subject: Re: some Excel automation questions Reply with quote



< How can I get from the Excel application object
the hWnd of Excel
Quote:


The Excel application object has a HWnd property.

< 2. How can I detect that the user closes Excel?
Quote:


This is far more difficult than it should be. MS recommend
using WaitForSingleObject to detect when Excel closes, and
there's a free component on my site that will do that for
you:
http://www.djpate.freeserve.co.uk/AutoOffc.htm#WaitForApp

However, this will only work if Excel quits completely. If
you have active references to it in your app, they will
prevent it from closing and the WaitForSingleObject method
won't work. In which case you're pretty much stuck with
using a timer to check regularly whether Excel is still
visible. :(

--
Deborah Pate (TeamB) http://delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html



Back to top
Erwin Kalvelagen
Guest





PostPosted: Tue Dec 16, 2003 5:46 pm    Post subject: Re: some Excel automation questions Reply with quote



Great. That all explains my questions.

Ooops. It seems I can not find the xlsappobj.hWnd property.
(Message: Method 'HWnd' not supported by automation object).
Is this the correct name?

Erwin

----------------------------------------------------------------
Erwin Kalvelagen
GAMS Development Corp., http://www.gams.com
[email]erwin (AT) gams (DOT) com[/email], http://www.gams.com/~erwin
----------------------------------------------------------------


"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote

Quote:
Erwin Kalvelagen:
How can I get from the Excel application object
the hWnd of Excel


The Excel application object has a HWnd property.

Erwin:
2. How can I detect that the user closes Excel?


This is far more difficult than it should be. MS recommend
using WaitForSingleObject to detect when Excel closes, and
there's a free component on my site that will do that for
you:
http://www.djpate.freeserve.co.uk/AutoOffc.htm#WaitForApp

However, this will only work if Excel quits completely. If
you have active references to it in your app, they will
prevent it from closing and the WaitForSingleObject method
won't work. In which case you're pretty much stuck with
using a timer to check regularly whether Excel is still
visible. :(

--
Deborah Pate (TeamB) http://delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html





Back to top
Deborah Pate (TeamB)
Guest





PostPosted: Tue Dec 16, 2003 6:19 pm    Post subject: Re: some Excel automation questions Reply with quote

< (Message: Method 'HWnd' not supported by automation
object). Is this the correct name?
Quote:


Yes, but come to think of it I think it was new with Excel
XP, sorry.

--
Deborah Pate (TeamB) http://delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html



Back to top
Erwin Kalvelagen
Guest





PostPosted: Tue Dec 16, 2003 6:43 pm    Post subject: Re: some Excel automation questions Reply with quote

Yes that seems to be the case. I will just add a try
except block: first try the appl.hwnd approach,
else try findwindow, else just do nothing. Thanks
a bunch for all the help!

Erwin

----------------------------------------------------------------
Erwin Kalvelagen
GAMS Development Corp., http://www.gams.com
[email]erwin (AT) gams (DOT) com[/email], http://www.gams.com/~erwin
----------------------------------------------------------------


"Deborah Pate (TeamB)" <d.pate (AT) blueyonder (DOT) co.not-this-bit.uk> wrote

Quote:
Erwin Kalvelagen:
(Message: Method 'HWnd' not supported by automation
object). Is this the correct name?


Yes, but come to think of it I think it was new with Excel
XP, sorry.

--
Deborah Pate (TeamB) http://delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html





Back to top
Deborah Pate (TeamB)
Guest





PostPosted: Tue Dec 16, 2003 7:15 pm    Post subject: Re: some Excel automation questions Reply with quote

< I will just add a try except block: first try the appl.hwnd
approach, else try findwindow, else just do nothing.
Quote:


The Application object has a Version property, which you
could use to avoid the exception, too.

--
Deborah Pate (TeamB) http://delphi-jedi.org

TeamB don't see posts sent via Google or ISPs
Use the real Borland server: newsgroups.borland.com
http://www.borland.com/newsgroups/genl_faqs.html



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi OLE Automation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.