Log in

View Full Version : Solved: Setting active window / focus to Excel



magelan
06-27-2013, 09:53 AM
Hi All,

I'm trying to set the active window to be my Excel window, like for instance if the user has minimzed Excel, I have an ontime event being called and i want the beginning of the event to un-minimize excel and make it the active window such that my userform will display [if excel is not the active window, the userform doesnt display].

I've seen object.setfocus but that seems to only be for items within excel.

I also saw application.windows(1).activate but i'm not sure that works.

Is there any way to force Excel to become un-minimzed or even just become the "active focused window" ?

Ringhal
07-01-2013, 03:30 AM
Here is something I have . Paste this code into "This Workbook".

Option Explicit

Private Sub Workbook_Open()

Call OnTime

End Sub

Public Sub OnTime()

'http://www.vbaexpress.com/forum/showthread.php?t=46682
On Error Resume Next
If Application.WindowState = xlMinimized Then
Application.WindowState = xlMaximized
End If
Application.OnTime EarliestTime:=Now + TimeValue("00:00:01"), Procedure:="ThisWorkbook.OnTime" ' set to 01 seconds

End Sub

magelan
07-15-2013, 12:45 PM
Here is something I have . Paste this code into "This Workbook".

Option Explicit

Private Sub Workbook_Open()

Call OnTime

End Sub

Public Sub OnTime()

'http://www.vbaexpress.com/forum/showthread.php?t=46682
On Error Resume Next
If Application.WindowState = xlMinimized Then
Application.WindowState = xlMaximized
End If
Application.OnTime EarliestTime:=Now + TimeValue("00:00:01"), Procedure:="ThisWorkbook.OnTime" ' set to 01 seconds

End Sub

That was perfect, by the way. Didnt want to leave you hanging. I already have an on-time and everything all setup but the application.windowstate=xlmaximized was just what i needed to steal focus & make sure my macros were running properly regardless of what the PC was doing.