Consulting

Results 1 to 5 of 5

Thread: auto show a window

  1. #1

    auto show a window

    hey i have been trying to get a window to come to the foreground on execution of a macro

    the macro is set to calculate the sheet every two minutes using application.ontime, What i am looking to do have the sheet show up in front of the other windows on the screen with every calculation

    [vba]
    Sub AutorecalcWorkbook()
    'refresh the workbook per 2 mins

    ThisWorkbook.Worksheets("Sheet1").Calculate
    ThisWorkbook.Worksheets("Sheet2").Calculate
    ThisWorkbook.Worksheets("Sheet3").Calculate



    dNextTime = Now + TimeValue("00:02:00")
    Application.OnTime dNextTime, "AutorecalcWorkbook"

    End Sub
    Sub showExcel()
    Excel.Application.Visible = True
    dNextTime = Now + TimeValue("00:02:00")
    Application.OnTime dNextTime, "ShowExcel"

    End Sub
    [/vba]
    i tried calling the show excel macro (without the ontime part) from the autocalc but nothing happened, when i run the macro manually from the vba window it brings the window to the foreground but when i call it from autocalc() it does nothing!

    its probably something simpleas always! any help appreciated!

    Cheers

    ed

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    I think you'll be wanting to include something along the lines of
    [VBA]Windows("TheWorkbookNameHere.xlsm").Activate[/VBA]
    instead of Application.Visible.
    Although if you have several windows open for the same workbook it may need to be more specific that that.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Quote Originally Posted by p45cal
    I think you'll be wanting to include something along the lines of
    [vba]Windows("TheWorkbookNameHere.xlsm").Activate[/vba] instead of Application.Visible.
    Although if you have several windows open for the same workbook it may need to be more specific that that.
    hey p45cal

    thanks for getting back, that works fine with other excel windows open in the workbook but what i was hoping to do is to bring the excel window up over other windows active on the computer, whether it be word, another excel or an internet browser..

    any ideas?!

  4. #4
    VBAX Mentor Teeroy's Avatar
    Joined
    Apr 2012
    Location
    Sydney, Australia
    Posts
    414
    Location
    You'd probably need a Windows API call. Have a look at http://www.everythingaccess.com/tuto...the-foreground and see if it helps.
    You'll likely end up with a combination of both this and P45cal's suggestions if you want something specific showing within excel when it becomes the foreground window..
    _________________________________________________________________________
    "In theory there is no difference between theory and practice. In practice there is." - Chuck Reid

    Any day you learn something new is a day not wasted.

  5. #5
    Quote Originally Posted by Teeroy
    You'd probably need a Windows API call. Have a look at http://www.everythingaccess.com/tuto...the-foreground and see if it helps.
    You'll likely end up with a combination of both this and P45cal's suggestions if you want something specific showing within excel when it becomes the foreground window..
    cheers Teeroy i'll give that a go

Posting Permissions

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