none
VBscript bring window to front

    Question

  • Hi all,

    I have a code here that opens an excel workbook.  However this script is launched from excel in the first place...(there is a button macro in an excel workbook i have that runs this script) ....  The issue is that this script opens the new workbook in a whole new application window (typically if you open 2 excel workbooks they are in the same "master" window) which is behind the window of the workbook that was already open

    however this would be ok if there was code i could add to the VBscript that brings the window it just opened to the front of all other windows open so its in view,  is this possible?
    Thursday, October 15, 2009 8:14 PM

Answers

  • Do you have the WSH help document downloaded?  See here:

    WSH 5.6 documentation download (URL all one line)
    http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

    Look up AppActivate.  However, you don't quite want to use it the way it is stated there (open loop).  The loop can be closed to give feedback as to success or failure, asAppActivate is actually a function that returns a boolean the indicates this (True/False) ...

    sWBTitle = "The title in the upper left of the workbook"
    set objShell = createobject("wscript.shell")
    if objShell.AppActivate(sWBTitle) then
      ' all's well continue
    else
      wsh.echo "Workbook: ", sWBTitle, "not found."
      wsh.quit
    end if

    Tom Lavedas
    • Marked as answer by xxentric Wednesday, November 04, 2009 5:08 AM
    Thursday, October 15, 2009 9:11 PM
    Moderator

All replies

  • Do you have the WSH help document downloaded?  See here:

    WSH 5.6 documentation download (URL all one line)
    http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9&displaylang=en

    Look up AppActivate.  However, you don't quite want to use it the way it is stated there (open loop).  The loop can be closed to give feedback as to success or failure, asAppActivate is actually a function that returns a boolean the indicates this (True/False) ...

    sWBTitle = "The title in the upper left of the workbook"
    set objShell = createobject("wscript.shell")
    if objShell.AppActivate(sWBTitle) then
      ' all's well continue
    else
      wsh.echo "Workbook: ", sWBTitle, "not found."
      wsh.quit
    end if

    Tom Lavedas
    • Marked as answer by xxentric Wednesday, November 04, 2009 5:08 AM
    Thursday, October 15, 2009 9:11 PM
    Moderator
  • Awesome! that worked perfectly.   You have been a huge help Tom!  :)
    Friday, October 16, 2009 4:32 AM