Consulting

Results 1 to 3 of 3

Thread: Solved: Setting active window / focus to Excel

  1. #1

    Solved: Setting active window / focus to Excel

    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" ?

  2. #2
    VBAX Regular
    Joined
    Jan 2013
    Posts
    84
    Location
    Here is something I have . Paste this code into "This Workbook".

    [vba]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[/vba]

  3. #3
    Quote Originally Posted by Ringhal
    Here is something I have . Paste this code into "This Workbook".

    [vba]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[/vba]
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •