|
-
Dec 2nd, 2009, 02:26 AM
#1
Thread Starter
Member
Event to detect when Excel gets focus
Hi all,
I’m trying to detect when Excel get focus. Well, actually I’m trying to detect when my workbook gets focus, but I want to detect when the focus is received from a different application.
All of these methods seems to detect when I switch between Excel windows, but not other applications.
vb Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Private Sub Workbook_Activate()
Private Sub Workbook_WindowActivate(ByVal Wn As Window)
Private Sub Application_WindowActivate(ByVal Wb As Workbook, ByVal Wn As Window)
Private Sub Application _WorkbookActivate(ByVal Wb As Workbook)
Does someone know how to do this?
Thanks,
-Terry
Cross post here:
http://www.xtremevbtalk.com/showthread.php?t=312278
-
Dec 2nd, 2009, 03:29 PM
#2
Re: Event to detect when Excel gets focus
those activate events only fire when a different sheet or workbook is activated in excel
you would have to use some API functions to find if excel gets focus, then run in a timer or something similar
check out GetActiveWindow API
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 3rd, 2009, 07:37 AM
#3
Thread Starter
Member
Re: Event to detect when Excel gets focus
Thanks for the input westconn.
I'm not sure about the effects of running a timer, but the gut feeling is that the system will be slowed down a little. The complexity also increases the chance of unexpected behaviour (due to errors or poor overall design).
I don't think I want to go down that path for the sake of a few cosmetic features...
-Terry
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|