Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Activate Excel application event
Is there any way to be notified when the Excel application is
activated, after some other application was the active application? I've enabled the Excel application-level events, but none of them fire when the Excel application is activated. Is there a Windows API function I can use? I looked at Appleman's Win32 API book but didn't see one. Any suggestions? Thanks, Greg |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Activate Excel application event
You'd need to sub-class Excel's window and trap messages, a lot more than
one API but you should find examples by Dan Appleman. However, in theory doable in VBA (I haven't attempted) but most likely to crash as soon as you touch the VBE while the code is running! If it's really important for you, and it's OK to have code permanently running, you can safely report all messages to Excel's window(s) with a C-dll and a fair amount of VBA. More details here - http://groups.google.co.uk/group/mic...3?dmode=source I forgot to include in that post, in the bas module I included following in the MessageEvent proc (this is where you'd include your own code to respond to new state of Excel's window) Public Sub MessageEvent(arg's Dim winState As Long, sWn As String winState = Application.WindowState If winState = xlMaximized Then sWn = "Maximised" ElseIf winState = xlMinimized Then sWn = "Minimized" Else sWn = "Normal" End If On Error Resume Next 'If uMsg Then Debug.Print "MSG : hWnd = " & CStr(hWnd) & "," _ ; uMsg = " & GetMsgSTR(uMsg) & ", _ wParam = " & CStr(wParam) & ", _ lParam = " & CStr(lParam)," _ ; "WinState = " & sWn 'End If also, experiment to filter which messages you are interested in Regards, Peter T "Greg Lovern" wrote in message ... Is there any way to be notified when the Excel application is activated, after some other application was the active application? I've enabled the Excel application-level events, but none of them fire when the Excel application is activated. Is there a Windows API function I can use? I looked at Appleman's Win32 API book but didn't see one. Any suggestions? Thanks, Greg |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Activate Excel application event
Not sure why I didn't think about a simple approach before. Unless you need
instantaneous notification the following might be close enough for most purposes. Public Declare Function GetActiveWindow Lib "user32" () As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As Long Sub StartChecking() CheckXLOnTime True End Sub Sub StopChecking() CheckXLOnTime False End Sub Sub CheckXLOnTime(bStart As Boolean) Static dt As Date If bStart Then dt = Now + TimeSerial(0, 0, 1) Application.OnTime dt, "CheckXLState" ElseIf dt 0 Then Application.OnTime dt, "CheckXLState", Schedule:=False dt = -1 End If End Sub Sub CheckXLState() Dim bNotActive As Boolean Dim bReCheck As Boolean Static bNotActiveLast As Boolean bNotActive = GetActiveWindow < FindWindow("XLMAIN", Application.Caption) bReCheck = True If bNotActiveLast < bNotActive Then bNotActiveLast = bNotActive If Not bNotActive Then ' Excel activated Call DoStuff(bReCheck) Else ' Excel de-activated End If End If If bReCheck Then CheckXLOnTime bReCheck End Sub Sub DoStuff(bCheck As Boolean) bCheck = MsgBox("Hi, back again..." & vbCr & vbCr & _ "OK to continue checking or Cancel to stop", vbOKCancel) = vbOK End Sub I hope it's obvious what to do; place the above in a normal module, run "StartChecking' then activate and de-activate Excel. When activated a message should pop up within a second. Regards, Peter T "Greg Lovern" wrote in message ... Is there any way to be notified when the Excel application is activated, after some other application was the active application? I've enabled the Excel application-level events, but none of them fire when the Excel application is activated. Is there a Windows API function I can use? I looked at Appleman's Win32 API book but didn't see one. Any suggestions? Thanks, Greg |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Activate Excel application event
Thanks, great idea. Regarding your earlier post, we have over 25,000 users (and growing) outside our organization using this workbook, and trying to have each of them run a setup program for a DLL or otherwise handle a DLL is out of the question. However, I don't need instant notification; this way should be fine. Thanks, Greg On Apr 19, 1:22 am, "Peter T" <peter_t@discussions wrote: Not sure why I didn't think about a simple approach before. Unless you need instantaneous notification the following might be close enough for most purposes. Public Declare Function GetActiveWindow Lib "user32" () As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As Long Sub StartChecking() CheckXLOnTime True End Sub Sub StopChecking() CheckXLOnTime False End Sub Sub CheckXLOnTime(bStart As Boolean) Static dt As Date If bStart Then dt = Now + TimeSerial(0, 0, 1) Application.OnTime dt, "CheckXLState" ElseIf dt 0 Then Application.OnTime dt, "CheckXLState", Schedule:=False dt = -1 End If End Sub Sub CheckXLState() Dim bNotActive As Boolean Dim bReCheck As Boolean Static bNotActiveLast As Boolean bNotActive = GetActiveWindow < FindWindow("XLMAIN", Application.Caption) bReCheck = True If bNotActiveLast < bNotActive Then bNotActiveLast = bNotActive If Not bNotActive Then ' Excel activated Call DoStuff(bReCheck) Else ' Excel de-activated End If End If If bReCheck Then CheckXLOnTime bReCheck End Sub Sub DoStuff(bCheck As Boolean) bCheck = MsgBox("Hi, back again..." & vbCr & vbCr & _ "OK to continue checking or Cancel to stop", vbOKCancel) = vbOK End Sub I hope it's obvious what to do; place the above in a normal module, run "StartChecking' then activate and de-activate Excel. When activated a message should pop up within a second. Regards, Peter T "Greg Lovern" wrote in message ... Is there any way to be notified when the Excel application is activated, after some other application was the active application? I've enabled the Excel application-level events, but none of them fire when the Excel application is activated. Is there a Windows API function I can use? I looked at Appleman's Win32 API book but didn't see one. Any suggestions? Thanks, Greg |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Activate Excel application event
Hmm, let me think, @ 10 cents per user ..... :-)
Peter T "Greg Lovern" wrote in message ... Thanks, great idea. Regarding your earlier post, we have over 25,000 users (and growing) outside our organization using this workbook, and trying to have each of them run a setup program for a DLL or otherwise handle a DLL is out of the question. However, I don't need instant notification; this way should be fine. Thanks, Greg On Apr 19, 1:22 am, "Peter T" <peter_t@discussions wrote: Not sure why I didn't think about a simple approach before. Unless you need instantaneous notification the following might be close enough for most purposes. Public Declare Function GetActiveWindow Lib "user32" () As Long Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As Long Sub StartChecking() CheckXLOnTime True End Sub Sub StopChecking() CheckXLOnTime False End Sub Sub CheckXLOnTime(bStart As Boolean) Static dt As Date If bStart Then dt = Now + TimeSerial(0, 0, 1) Application.OnTime dt, "CheckXLState" ElseIf dt 0 Then Application.OnTime dt, "CheckXLState", Schedule:=False dt = -1 End If End Sub Sub CheckXLState() Dim bNotActive As Boolean Dim bReCheck As Boolean Static bNotActiveLast As Boolean bNotActive = GetActiveWindow < FindWindow("XLMAIN", Application.Caption) bReCheck = True If bNotActiveLast < bNotActive Then bNotActiveLast = bNotActive If Not bNotActive Then ' Excel activated Call DoStuff(bReCheck) Else ' Excel de-activated End If End If If bReCheck Then CheckXLOnTime bReCheck End Sub Sub DoStuff(bCheck As Boolean) bCheck = MsgBox("Hi, back again..." & vbCr & vbCr & _ "OK to continue checking or Cancel to stop", vbOKCancel) = vbOK End Sub I hope it's obvious what to do; place the above in a normal module, run "StartChecking' then activate and de-activate Excel. When activated a message should pop up within a second. Regards, Peter T "Greg Lovern" wrote in message ... Is there any way to be notified when the Excel application is activated, after some other application was the active application? I've enabled the Excel application-level events, but none of them fire when the Excel application is activated. Is there a Windows API function I can use? I looked at Appleman's Win32 API book but didn't see one. Any suggestions? Thanks, Greg |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Activate Event Before Saving | Excel Programming | |||
Trigger an Excel VBA event from another application | Excel Programming | |||
activate excel application after userform activation in modaless | Excel Programming | |||
On activate event | Excel Programming | |||
Activate event | Excel Programming |