From: Robert Crandal on 9 Dec 2009 03:09 I need to be able to detect the event when someone minimizes or restores the Excel application, or switches to another application. How can I do these?? (if it's even possible) Thanks folks!
From: Dee Earley on 9 Dec 2009 03:56 On 09/12/2009 08:09, Robert Crandal wrote: > I need to be able to detect the event when someone > minimizes or restores the Excel application, or > switches to another application. > > How can I do these?? (if it's even possible) You'll probably get more of a reply in the Excel VBA groups. -- Dee Earley (dee.earley(a)icode.co.uk) i-Catcher Development Team iCode Systems
From: Robert Crandal on 9 Dec 2009 04:44 But they told me to come and ask here! 8( "Dee Earley" <dee.earley(a)icode.co.uk> wrote in message news:e8bcG2KeKHA.4724(a)TK2MSFTNGP05.phx.gbl... > > You'll probably get more of a reply in the Excel VBA groups. > > --
From: RB Smissaert on 9 Dec 2009 05:20 That was me and yes, it looks you can't do this in VBA and nobody in the Excel group has come up with an answer yet. It is easy to detect the resize of the workbook window, but not the main Excel application window. RBS "Robert Crandal" <nobody(a)gmail.com> wrote in message news:_jKTm.78597$W77.41608(a)newsfe11.iad... > But they told me to come and ask here! 8( > > > "Dee Earley" <dee.earley(a)icode.co.uk> wrote in message > news:e8bcG2KeKHA.4724(a)TK2MSFTNGP05.phx.gbl... >> >> You'll probably get more of a reply in the Excel VBA groups. >> >> -- >
From: Nobody on 9 Dec 2009 08:07
"Robert Crandal" <nobody(a)gmail.com> wrote in message news:ZWITm.49702$ky1.19872(a)newsfe14.iad... >I need to be able to detect the event when someone > minimizes or restores the Excel application, or > switches to another application. > > How can I do these?? (if it's even possible) The sample code below was tested with Excel 2002. It uses Application.hWnd, which seems to be new in Excel 2002. For Excel 2000 and below, there are various API ways. If you have any hWnd for any window in Excel, you can use GetAncestor(GA_ROOT) to get hWnd for the main window. Also, rather than using WindowState property below, you can use the API function IsIconic() to see if a window is minimized. To try this sample, add Timer1 to Form1, and a reference to " Microsoft Excel X.X Object Library", then use the following code: Option Explicit Private Declare Function GetForegroundWindow Lib "user32" () As Long Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long Dim oExcelApp As Excel.Application Private Sub Form_Load() Set oExcelApp = New Excel.Application oExcelApp.Visible = True Timer1.Interval = 500 End Sub Private Sub Form_Unload(Cancel As Integer) oExcelApp.Quit Set oExcelApp = Nothing End Sub Private Sub Timer1_Timer() Debug.Print "IsIconic = " & (IsIconic(oExcelApp.hwnd) <> 0); Debug.Print ", Minimized = " & (oExcelApp.WindowState = xlMinimized); Debug.Print ", ForegroundWindow = " & (GetForegroundWindow() = _ oExcelApp.hwnd) End Sub |