PDA

View Full Version : auto show a window



edthehorse
11-21-2012, 04:22 AM
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


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

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

p45cal
11-21-2012, 07:18 AM
I think you'll be wanting to include something along the lines of
Windows("TheWorkbookNameHere.xlsm").Activate
instead of Application.Visible.
Although if you have several windows open for the same workbook it may need to be more specific that that.

edthehorse
11-21-2012, 10:28 AM
I think you'll be wanting to include something along the lines of
Windows("TheWorkbookNameHere.xlsm").Activate 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?!

Teeroy
11-21-2012, 08:25 PM
You'd probably need a Windows API call. Have a look at http://www.everythingaccess.com/tutorials.asp?ID=Bring-an-external-application-window-to-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..

edthehorse
11-23-2012, 04:47 AM
You'd probably need a Windows API call. Have a look at http://www.everythingaccess.com/tutorials.asp?ID=Bring-an-external-application-window-to-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