+ Reply to Thread
Results 1 to 3 of 3

Run-time error '91' with IE App

  1. #1
    Registered User
    Join Date
    12-01-2010
    Location
    Savannah, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Run-time error '91' with IE App

    Hi all, this is my first post and I am an excel vba hack.

    I have an spreadsheet with a list of companies. Each cell contains a company name, i.e., XYZ Factory. I want to assign a hyperlink to the cell that will take the users to that company's web-site. To automate the process, I am taking the cell contents (XYZ Factory) and performing a Google "I'm feeling lucky" search. The resultant URL is then placed in a hyperlink associated with that cell.

    The code runs perfectly in "debug" mode when I am stepping through. However, when I release it to run ... I encounter a Run-Time error '91'. The code stops on the following line

    IEdoc.all("q").Value = searchtext

    As I said, I am a bit of a hack. Do i need to reset variable or clear memory? I am at a loss.

    Here is the code.
    Please Login or Register  to view this content.
    Last edited by cadkins; 12-02-2010 at 02:40 PM. Reason: Added Code Tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Run-time error '91' with IE App

    Hello cadkins,

    Welcome to the forum!

    The problem has to with timing. While stepping through the code, more time passes allowing for the web page to load. You're probably saying, "I have a loop to tell me when the web page has finished loading." The method you used works, but is not reliable. The browser may not be busy, but that doesn't mean the page is completed loaded. This is signaled by the ReadyState property being set to 4.

    To make your macro more robust, I have added a time out routine. Currently the time out period is 10 seconds. You can make this longer or shorter if wish. Once the time out occurs, a message box informs you a time out has occurred. The web browser is displayed after dismissing the message, so you can see why this happened.

    The API calls are needed to switch between Excel and Internet Explorer. Without these calls, the message boxes will be hidden until the user clicks on cell in Excel. During a time out, the browser window must be displayed on top of Excel.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-01-2010
    Location
    Savannah, Georgia
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Run-time error '91' with IE App

    Thanks, I am putting the code in now an walking through it. This is a great learning experience and I appreciate your time in helping my fix this problem. I'll be back in a few to post the results.

+ 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