Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 224
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 224
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Activate Event Before Saving J-D[_2_] Excel Programming 2 May 10th 07 11:08 PM
Trigger an Excel VBA event from another application Mike[_113_] Excel Programming 4 December 14th 06 09:21 AM
activate excel application after userform activation in modaless x taol Excel Programming 6 January 29th 06 01:31 PM
On activate event SHIPP Excel Programming 5 December 30th 05 04:43 PM
Activate event Lynn[_3_] Excel Programming 2 September 13th 03 09:30 PM


All times are GMT +1. The time now is 03:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"