Get Focus to window using VB script and SendKeys

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Unknown90
    New Member
    • Oct 2012
    • 3

    Get Focus to window using VB script and SendKeys

    Hello Experts,
    I am working on automating a login to a webpage using SendKeys. The problem I am having is that I am trying to figure out how to get the Internet window in Focus so that way it can run the commands and not keep looping. My code is below:

    Thanks,
    Steve

    Code:
    Set IE = CreateObject("InternetExplorer.Application") 
    set WshShell = WScript.CreateObject("WScript.Shell")
    IE.Navigate "http://www.WebsiteName.com"
    IE.Visible = True
    Wscript.Sleep 6000 
    IE.Document.All.Item("email").Value = "UserName" 
    IE.Document.All.Item("pass").Value = "Password"
    WshShell.SendKeys "{TAB}"
    WshShell.SendKeys "{TAB}"  
    WshShell.SendKeys "{ENTER}"
    Last edited by Rabbit; Oct 12 '12, 08:43 PM. Reason: Please use code tags when posting code.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    What is the tab tab enter for? Is that to submit the form? You can use IE.Document.for ms(0).submit() where 0 is the index of the form. In this case, it will submit the first form. If it's not the first form, you'll just have to find the correct index.

    Comment

    • Unknown90
      New Member
      • Oct 2012
      • 3

      #3
      The tab tab enter was to submit the information to the webpage and login. It took two tabs from the password field to login.btn so thats why they were in there.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Yeah, you don't need to do that. You can just use the method in my post instead. It's more reliable.

        Comment

        • Unknown90
          New Member
          • Oct 2012
          • 3

          #5
          Ok great. Thank you for your help.

          Comment

          Working...