+ Reply to Thread
Results 1 to 5 of 5

need help in making the current window as active window.

  1. #1
    Registered User
    Join Date
    09-09-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    need help in making the current window as active window.

    hi,

    I have created a macro to access web page using VBA in Excel.
    The macro is working as per the code.
    But while the macro is running, if i switch to some other window, it executes the rest of the macro commands there.
    For E.g.:
    I run macro to open google, and then use SendKeys to enter the string in the search and use SendKeys again to Tab thru the page 2 times, till i reach I'm Feeling Lucky button. then press enter.

    When i click run, the web page opens and the google is displayed. And rest works fine as wel.
    but while it's running, if i open other any other application, for e.g. word doc, then the rest of the code, like Tabbing for 2 times, is done in that word.

    Can anyone suggest a code which can activate the window used by macro, n use it by default for further actions, even if i navigate away from the window?

    My code is:

    Dim newIE As Object
    Dim newHour
    Dim newMinute
    Dim newSecond
    Dim waitTime



    Set newIE = CreateObject("InternetExplorer.Application")
    newIE.Navigate "http://google.com/"
    newIE.Visible = True

    newHour = Hour(Now())
    newMinute = Minute(Now())
    newSecond = Second(Now()) + 10
    waitTime = TimeSerial(newHour, newMinute, newSecond)
    Application.Wait waitTime


    SendKeys "XYZ"
    SendKeys "{TAB 2}", True
    SendKeys "{ENTER}", True


    Thanks in advance

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: need help in making the current window as active window.

    Try declaring the workbook you are using and then use it. You didn't give all your code so I'm going to show you a general use of declaring the workbook:
    Please Login or Register  to view this content.
    Please note my usage of code tags here at the Excel Forum. Whenever you want to display code please use them as it makes it easier to view/copy/use your code. See the forum rules.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    09-09-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: need help in making the current window as active window.

    Thank u so much.... it's working perfectly as expected
    As this is for the worksheet, can u also tell me how can i replicate this same kind of behavior for the web page.
    I mean, i want the macro to be running to execute commands and act accordingly on the web page selected, even if i navigate away from it...

    Thanks again n sorry for the inconvenience

  4. #4
    Registered User
    Join Date
    09-09-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: need help in making the current window as active window.

    Bump no response

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: need help in making the current window as active window.

    I don't think that Excel can do that although I may be wrong. Judging by the lack of response, I'm guessing it can't. If you want to watch specific webpages than you would be better off moving into VB.NET, C#, or Java (or other programming languages).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1