Activating Word and IE using AutoIe and Windows script

Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

I created a .vbs file using AutoIt code to activate the open instance of
Word. It works fine, and is faster than the Windows script I had used
for the same purpose:

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
oAutoIt.WinActivate "Microsoft Word", ""

However, I couldn't do same thing with IE, because with AutoIt the title
must include the specific title that appears, and with IE the first
thing that appears is not "Internet Explorer" but the title of the
particular document, and there's no way to know what that title will be.
So I couldn't get this AutoIt code to work for IE:

Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
' [none of these three alternative lines would work]
oAutoIt.WinActivate "Title - Internet Explorer", ""
oAutoIt.WinActivate "Internet Explorer", ""
oAutoIt.WinActivate """ - Internet Explorer", ""

So I went back and used regular Windows script instead that I had
previously used for Word, and it works for IE. This activates the most
recently activated instance of IE:

Option Explicit
dim w

With WScript.CreateObject("WScript.Shell")
w = .AppActivate("Internet Explorer")
End With

This is a great convenience, which I recommend to anyone. Suppose I
have eight windows open including two IE windows and I want to do a
google search. I want to open one of the IE windows in order to access
the Google toolbar that is installed on my IE. I either have to hit
Alt+Tab several times to get to one of the IE instances, or reach for
the Mouse and click the pointer on the taskbar, which is inefficient.
But with this .vbs file, all I do is press Winkey+G which I've assigned
to the .vbs file. That instantly activates the most recently activated
IE window, and then I press Alt+G to put the cursor in the Google search
window in the Google toolbar. Something that use to take a few steps is
now almost instant.

Larry
11 answers Last reply
More about activating word autoie windows script
  1. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Larry wrote:

    > I created a .vbs file using AutoIt code to activate the open instance of
    > Word. It works fine, and is faster than the Windows script I had used
    > for the same purpose:
    >
    > Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
    > oAutoIt.WinActivate "Microsoft Word", ""
    >
    > However, I couldn't do same thing with IE, because with AutoIt the title
    > must include the specific title that appears, and with IE the first
    > thing that appears is not "Internet Explorer" but the title of the
    > particular document, and there's no way to know what that title will be.
    > So I couldn't get this AutoIt code to work for IE:
    >
    > Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
    > ' [none of these three alternative lines would work]
    > oAutoIt.WinActivate "Title - Internet Explorer", ""
    > oAutoIt.WinActivate "Internet Explorer", ""
    > oAutoIt.WinActivate """ - Internet Explorer", ""
    >
    > (snip)
    Hi,

    AutoIt(X) operates in one of four "Window matching" modes. The modes
    are set with the AutoItSetOption function using the WinTitleMatchMode
    option. To specify ANY substring of the window title you want to match,
    set the mode to 2. Also, the Windows titles and text are case
    sensitive. More about the different modes in AutoItX's help file.

    Example that should make it work for you:

    Set oAutoIt = CreateObject("AutoItX3.Control")
    oAutoIt.AutoItSetOption "WinTitleMatchMode", 2
    oAutoIt.WinActivate "Internet Explorer", ""


    --
    torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    Administration scripting examples and an ONLINE version of
    the 1328 page Scripting Guide:
    http://www.microsoft.com/technet/scriptcenter/default.mspx
  2. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Yes, that works. .Thanks.

    But the AutoIt Help files seem rather skimpy as to details.

    Another question: Could I use AutoIt to close all open windows?

    Larry


    "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
    news:eDEafcelFHA.3828@TK2MSFTNGP12.phx.gbl...
    > Larry wrote:
    >
    > > I created a .vbs file using AutoIt code to activate the open
    instance of
    > > Word. It works fine, and is faster than the Windows script I had
    used
    > > for the same purpose:
    > >
    > > Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
    > > oAutoIt.WinActivate "Microsoft Word", ""
    > >
    > > However, I couldn't do same thing with IE, because with AutoIt the
    title
    > > must include the specific title that appears, and with IE the first
    > > thing that appears is not "Internet Explorer" but the title of the
    > > particular document, and there's no way to know what that title will
    be.
    > > So I couldn't get this AutoIt code to work for IE:
    > >
    > > Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
    > > ' [none of these three alternative lines would work]
    > > oAutoIt.WinActivate "Title - Internet Explorer", ""
    > > oAutoIt.WinActivate "Internet Explorer", ""
    > > oAutoIt.WinActivate """ - Internet Explorer", ""
    > >
    > > (snip)
    > Hi,
    >
    > AutoIt(X) operates in one of four "Window matching" modes. The modes
    > are set with the AutoItSetOption function using the WinTitleMatchMode
    > option. To specify ANY substring of the window title you want to
    match,
    > set the mode to 2. Also, the Windows titles and text are case
    > sensitive. More about the different modes in AutoItX's help file.
    >
    > Example that should make it work for you:
    >
    > Set oAutoIt = CreateObject("AutoItX3.Control")
    > oAutoIt.AutoItSetOption "WinTitleMatchMode", 2
    > oAutoIt.WinActivate "Internet Explorer", ""
    >
    >
    > --
    > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    > Administration scripting examples and an ONLINE version of
    > the 1328 page Scripting Guide:
    > http://www.microsoft.com/technet/scriptcenter/default.mspx
  3. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Yeah, I see. In the Help index, it's under Windows Title and Text
    (Advanced)


    Larry wrote:
    > Yes, that works. .Thanks.
    >
    > But the AutoIt Help files seem rather skimpy as to details.
    >
    > Another question: Could I use AutoIt to close all open windows?
    >
    > Larry
    >
    >
    >
    > "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in
    > message news:eDEafcelFHA.3828@TK2MSFTNGP12.phx.gbl...
    > > Larry wrote:
    > >
    > > > I created a .vbs file using AutoIt code to activate the open
    > instance of
    > > > Word. It works fine, and is faster than the Windows script I had
    > used
    > > > for the same purpose:
    > > >
    > > > Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
    > > > oAutoIt.WinActivate "Microsoft Word", ""
    > > >
    > > > However, I couldn't do same thing with IE, because with AutoIt the
    > title
    > > > must include the specific title that appears, and with IE the
    > > > first thing that appears is not "Internet Explorer" but the title
    > > > of the particular document, and there's no way to know what that
    > > > title will
    > be.
    > > > So I couldn't get this AutoIt code to work for IE:
    > > >
    > > > Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
    > > > ' [none of these three alternative lines would work]
    > > > oAutoIt.WinActivate "Title - Internet Explorer", ""
    > > > oAutoIt.WinActivate "Internet Explorer", ""
    > > > oAutoIt.WinActivate """ - Internet Explorer", ""
    > > >
    > > > (snip)
    > > Hi,
    > >
    > > AutoIt(X) operates in one of four "Window matching" modes. The modes
    > > are set with the AutoItSetOption function using the
    > > WinTitleMatchMode option. To specify ANY substring of the window
    > > title you want to
    > match,
    > > set the mode to 2. Also, the Windows titles and text are case
    > > sensitive. More about the different modes in AutoItX's help file.
    > >
    > > Example that should make it work for you:
    > >
    > > Set oAutoIt = CreateObject("AutoItX3.Control")
    > > oAutoIt.AutoItSetOption "WinTitleMatchMode", 2
    > > oAutoIt.WinActivate "Internet Explorer", ""
    > >
    > >
    > > --
    > > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    > > Administration scripting examples and an ONLINE version of
    > > the 1328 page Scripting Guide:
    > > http://www.microsoft.com/technet/scriptcenter/default.mspx
  4. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Now I've created an .au3 file to activate IE and (while I may be
    imagining it) it seems to work slightly faster than the .vbs version of
    the same code. So I'm going with the au3.


    "Larry" <larry328NOSPAM@att.net> wrote in message
    news:eVk5VcglFHA.3148@TK2MSFTNGP09.phx.gbl...
    > Yes, that works. .Thanks.
    >
    > But the AutoIt Help files seem rather skimpy as to details.
    >
    > Another question: Could I use AutoIt to close all open windows?
    >
    > Larry
    >
    >
    >
    > "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in
    message
    > news:eDEafcelFHA.3828@TK2MSFTNGP12.phx.gbl...
    > > Larry wrote:
    > >
    > > > I created a .vbs file using AutoIt code to activate the open
    > instance of
    > > > Word. It works fine, and is faster than the Windows script I had
    > used
    > > > for the same purpose:
    > > >
    > > > Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
    > > > oAutoIt.WinActivate "Microsoft Word", ""
    > > >
    > > > However, I couldn't do same thing with IE, because with AutoIt the
    > title
    > > > must include the specific title that appears, and with IE the
    first
    > > > thing that appears is not "Internet Explorer" but the title of the
    > > > particular document, and there's no way to know what that title
    will
    > be.
    > > > So I couldn't get this AutoIt code to work for IE:
    > > >
    > > > Set oAutoIt = WScript.CreateObject("AutoItX3.Control")
    > > > ' [none of these three alternative lines would work]
    > > > oAutoIt.WinActivate "Title - Internet Explorer", ""
    > > > oAutoIt.WinActivate "Internet Explorer", ""
    > > > oAutoIt.WinActivate """ - Internet Explorer", ""
    > > >
    > > > (snip)
    > > Hi,
    > >
    > > AutoIt(X) operates in one of four "Window matching" modes. The modes
    > > are set with the AutoItSetOption function using the
    WinTitleMatchMode
    > > option. To specify ANY substring of the window title you want to
    > match,
    > > set the mode to 2. Also, the Windows titles and text are case
    > > sensitive. More about the different modes in AutoItX's help file.
    > >
    > > Example that should make it work for you:
    > >
    > > Set oAutoIt = CreateObject("AutoItX3.Control")
    > > oAutoIt.AutoItSetOption "WinTitleMatchMode", 2
    > > oAutoIt.WinActivate "Internet Explorer", ""
    > >
    > >
    > > --
    > > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    > > Administration scripting examples and an ONLINE version of
    > > the 1328 page Scripting Guide:
    > > http://www.microsoft.com/technet/scriptcenter/default.mspx
    >
    >
  5. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Larry wrote:

    > Yes, that works. .Thanks.
    >
    > But the AutoIt Help files seem rather skimpy as to details.
    >
    > Another question: Could I use AutoIt to close all open windows?
    >
    Hi,

    With AutoIt (the standalone script language), yes, with AutoItX (the
    component you use from VBScript), no.

    The reason for this is that AutoIt have a WinList function that can
    return an array of all top-level windows, while this function is
    missing in the AutoItX component (but who knows, maybe it will be
    added in a later version).


    --
    torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    Administration scripting examples and an ONLINE version of
    the 1328 page Scripting Guide:
    http://www.microsoft.com/technet/scriptcenter/default.mspx
  6. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Well, here's some sample code from AutoIt Help. I put this in an .au3
    file and it makes a series of msg boxes appear each with the title of an
    open window along with some other information. The language is quite
    different from VB and I don't know how to manipulate it How would I
    make this simply close all the open Windows (and of course ask for
    changes to be saved if that's needed)?


    $var = WinList()

    For $i = 1 to $var[0][0]
    ; Only display visble windows that have a title
    If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" &
    $var[$i][1])
    EndIf
    Next

    Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
    Else
    Return 0
    EndIf

    EndFunc


    Torgeir Bakken (MVP) wrote:
    > Larry wrote:
    >
    > > Yes, that works. .Thanks.
    > >
    > > But the AutoIt Help files seem rather skimpy as to details.
    > >
    > > Another question: Could I use AutoIt to close all open windows?
    > >
    > Hi,
    >
    > With AutoIt (the standalone script language), yes, with AutoItX (the
    > component you use from VBScript), no.
    >
    > The reason for this is that AutoIt have a WinList function that can
    > return an array of all top-level windows, while this function is
    > missing in the AutoItX component (but who knows, maybe it will be
    > added in a later version).
  7. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Larry wrote:

    > Well, here's some sample code from AutoIt Help. I put this in an .au3
    > file and it makes a series of msg boxes appear each with the title of an
    > open window along with some other information. The language is quite
    > different from VB and I don't know how to manipulate it How would I
    > make this simply close all the open Windows (and of course ask for
    > changes to be saved if that's needed)?
    >
    >
    > $var = WinList()
    >
    > For $i = 1 to $var[0][0]
    > ; Only display visble windows that have a title
    > If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    > MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" &
    > $var[$i][1])
    > EndIf
    > Next
    >
    > Func IsVisible($handle)
    > If BitAnd( WinGetState($handle), 2 ) Then
    > Return 1
    > Else
    > Return 0
    > EndIf
    >
    > EndFunc
    >
    Hi,

    Instead of feeding the found titles into the MsgBox function, feed
    it into the WinClose function instead.


    --
    torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    Administration scripting examples and an ONLINE version of
    the 1328 page Scripting Guide:
    http://www.microsoft.com/technet/scriptcenter/default.mspx
  8. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Sorry for asking questions from such a newbie level here, but I got it
    to work, sort of, with the below. However, this will not close
    minimized windows. (I thought by "visible" maybe it meant "non
    minimized," but when I commented out the second half of the If Then line
    ("Is Visible" etc.) it attempted to close Windows itself.)

    Also if a Save As dialog appears, it blinks off and on several times
    before become steady, instead of just appearing and waiting for a
    response.

    Also, how would I exclude an application, say Word, from this? I tried
    adding this to the If Then line
    And $var[$i][0] <> "Microsoft Word"
    But it closed Word anyway.


    $var = WinList()

    For $i = 1 to $var[0][0]
    ; Only display visble windows that have a title
    If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    WinClose("")
    EndIf
    Next

    Func IsVisible($handle)
    If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
    Else
    Return 0
    EndIf

    EndFunc


    "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
    news:OECfB7olFHA.3288@TK2MSFTNGP09.phx.gbl...
    > Larry wrote:
    >
    > > Well, here's some sample code from AutoIt Help. I put this in an
    ..au3
    > > file and it makes a series of msg boxes appear each with the title
    of an
    > > open window along with some other information. The language is
    quite
    > > different from VB and I don't know how to manipulate it How would I
    > > make this simply close all the open Windows (and of course ask for
    > > changes to be saved if that's needed)?
    > >
    > >
    > > $var = WinList()
    > >
    > > For $i = 1 to $var[0][0]
    > > ; Only display visble windows that have a title
    > > If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    > > MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" &
    > > $var[$i][1])
    > > EndIf
    > > Next
    > >
    > > Func IsVisible($handle)
    > > If BitAnd( WinGetState($handle), 2 ) Then
    > > Return 1
    > > Else
    > > Return 0
    > > EndIf
    > >
    > > EndFunc
    > >
    > Hi,
    >
    > Instead of feeding the found titles into the MsgBox function, feed
    > it into the WinClose function instead.
    >
    >
    >
    > --
    > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    > Administration scripting examples and an ONLINE version of
    > the 1328 page Scripting Guide:
    > http://www.microsoft.com/technet/scriptcenter/default.mspx
  9. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Larry wrote:

    > Sorry for asking questions from such a newbie level here, but I got it
    > to work, sort of, with the below. However, this will not close
    > minimized windows. (I thought by "visible" maybe it meant "non
    > minimized," but when I commented out the second half of the If Then line
    > ("Is Visible" etc.) it attempted to close Windows itself.)
    >
    > Also if a Save As dialog appears, it blinks off and on several times
    > before become steady, instead of just appearing and waiting for a
    > response.
    >
    > Also, how would I exclude an application, say Word, from this? I tried
    > adding this to the If Then line
    > And $var[$i][0] <> "Microsoft Word"
    > But it closed Word anyway.
    >
    > (snip AutoIt v3 code)
    Hi,

    I'm not an expert on AutoIt v3 code, I suggest you ask in the
    "v3 Support" forum at http://www.autoitscript.com/forum/index.php?


    --
    torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    Administration scripting examples and an ONLINE version of
    the 1328 page Scripting Guide:
    http://www.microsoft.com/technet/scriptcenter/default.mspx
  10. Archived from groups: microsoft.public.scripting.vbscript,microsoft.public.win98.gen_discussion (More info?)

    Thanks, I'll check it out.

    Larry


    "Torgeir Bakken (MVP)" <Torgeir.Bakken-spam@hydro.com> wrote in message
    news:e6GFDZqlFHA.2156@TK2MSFTNGP14.phx.gbl...
    > Larry wrote:
    >
    > > Sorry for asking questions from such a newbie level here, but I got
    it
    > > to work, sort of, with the below. However, this will not close
    > > minimized windows. (I thought by "visible" maybe it meant "non
    > > minimized," but when I commented out the second half of the If Then
    line
    > > ("Is Visible" etc.) it attempted to close Windows itself.)
    > >
    > > Also if a Save As dialog appears, it blinks off and on several times
    > > before become steady, instead of just appearing and waiting for a
    > > response.
    > >
    > > Also, how would I exclude an application, say Word, from this? I
    tried
    > > adding this to the If Then line
    > > And $var[$i][0] <> "Microsoft Word"
    > > But it closed Word anyway.
    > >
    > > (snip AutoIt v3 code)
    > Hi,
    >
    > I'm not an expert on AutoIt v3 code, I suggest you ask in the
    > "v3 Support" forum at http://www.autoitscript.com/forum/index.php?
    >
    >
    > --
    > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
    > Administration scripting examples and an ONLINE version of
    > the 1328 page Scripting Guide:
    > http://www.microsoft.com/technet/scriptcenter/default.mspx
  11. hey i found a cheat for a game i use (last chaos) they told me to copy and paste it but how do i activate it on autoit is where it told me 2 put the code if u can tell me plz my email adress is bengy_widener@yahoo.com
Ask a new question

Read More

Internet Explorer Microsoft Windows