+ Reply to Thread
Results 1 to 8 of 8

Pull URL from IE to store as Variable in Excel

  1. #1
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Pull URL from IE to store as Variable in Excel

    Hi everyone I am getting stuck on a program I am writing at work.

    What I'm attempting to do: I have an excel sheet program, this excel program will open IE and navigate to a website (newegg for example) when the website loads, it will insert a stored variable from the excel sheet into the search field of the website (sony battery for example). Once the new page loads, the URL of the new page is then stored as a variable.

    Is this even possible to do with VBA?

    any help is much appreciated

    here is what I have so far: New IE window opens and is directed to the site

    Please Login or Register  to view this content.
    odo-

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628

    Re: Pull URL from IE to store as Variable in Excel

    You can use this code (the lines in blue should be changed to any html page):
    Please Login or Register  to view this content.
    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Re: Pull URL from IE to store as Variable in Excel

    Antonio,

    Thanks for your fast reply. I tried to run your code but I got this error: Compile Error - User defined type not defined. It is highlighting "objIE As InternetExplorer". I edited your code slightly, and it strated to work until it got to "For r = 2 To lastRow" Here is my edited code. I also set a reference to "Microsoft Browser Helper" I am not sure if this is the correct one..

    Please Login or Register  to view this content.
    It goes strait to the lbl_exit due to the error.

    I'm not very proficient in VBA... I am confused about what "For r = 2 To lastRow" is trying to do.

    Thanks again!

    odo-
    Last edited by odo; 05-15-2009 at 03:52 PM.

  4. #4
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Re: Pull URL from IE to store as Variable in Excel

    Antonio,

    THANK YOU SO MUCH, I was playing around with it and firgured out that its copying and pasting what is in Column A, Row 2 into the search field! PERFECT! it is also extracting the URL! I am modifying the code.

  5. #5
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Re: Pull URL from IE to store as Variable in Excel

    Hello,

    I have managed to customize the code to the program I a working on but am having problems at this point:

    Please Login or Register  to view this content.
    While it works for newegg, it does not work for the website I need it for. I understand that ("desciption") is refering to the name of the search input field for the newegg website. I have successfuly customized that part but where I'm having problems is with the " 'click on 'go' " part. The website I'm using this program for uses the name "submit" which I replaced with (4) but it doesn't seem to work.

    My question: for the 'click on 'go' part, what is ("input") and (4) refering to? How can I alter this code for my website?

    Here is the altered code:

    Please Login or Register  to view this content.
    Thanks any help is much appreciated!

    odo-

  6. #6
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Re: Pull URL from IE to store as Variable in Excel

    Here is the HTML code

    Please Login or Register  to view this content.
    I've literally spent all day trying to figure out this small thing. I know its probably not why, but am I not getting the click part because the name properties for the image button is put at the end and not in the front right after input type?

    odo-

  7. #7
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Re: Pull URL from IE to store as Variable in Excel

    bump, how do I define the "search" button?

  8. #8
    Registered User
    Join Date
    05-01-2009
    Location
    Seattle
    MS-Off Ver
    Excel 2003, Excel 2007
    Posts
    21

    Re: Pull URL from IE to store as Variable in Excel

    YES I figured it out, thanks everyone for your help here is what was going on:

    The Problem: I was trying to reference a specific control from the website, but the website had two controls that were named the same thing - "Submit".

    Here is the section of the HTML code from the site:

    Please Login or Register  to view this content.
    SOLUTION: To resolve the problem, you have to index the tags named submit, it is zero based so the first instance is actually indexed as 0 and the second is indexed as 1.

    Here is the section of the VBA BEFORE code:

    Please Login or Register  to view this content.
    Here is the section of the VBA AFTER code:

    Please Login or Register  to view this content.
    This was driving me nuts, hope this helps out other people. Also heres a good link to refer to:

    http://msdn.microsoft.com/en-us/libr...76(VS.85).aspx

    http://msdn.microsoft.com/en-us/libr...9(VS.85).aspx#

    odo-

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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