+ Reply to Thread
Results 1 to 10 of 10

Import Web Data VBA "sometimes working"

  1. #1
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Import Web Data VBA "sometimes working"

    Hello,
    I have written some VBA code that will reach out to a URL link and will import external data into Excel. The code works great, well…..every once in a while. After getting the code to run all the way through and import the web query, I saved the file and closed it. When I reopened the file, and tried running the same code, it errors out. I am wondering if I break the connection/link once I close the file. Another weird thing is even though the code errors out, if I go import the URL manually by going to Data > External Data > From Web and I begin to import the URL, Excel keeps asking me the following:

    “Do you want to view only the webpage content that was delivered securely? This webpage contains content that will not be delivered using a secure HTTPS connection, which could compromise the security of the entire webpage.”

    Excel will ask this to me maybe 3-4 times for the URL link I am attempting to import. However this isn’t the weird thing…Once I press yes and the URL is loaded properly, then I import the data, the VBA coding that I wrote will work properly and will run all the way through. As long as I don’t close the file, I can keep refreshing/importing the data as much as I want to. I’d like to create a loop to basically skip any errors as well as any security warnings until the VBA code will load/refresh the data from the URL. Can anyone help me with this error loop? The code below is what I have to import my data and is working well when I have the file open. Thank you!!

    Please Login or Register  to view this content.

    NOTE: The URL link I have provided is NOT the actual link I am attempting to import. I put this URL only because the link I am trying to get to is confidential and holds propiertary information.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import Web Data VBA "sometimes working"

    Try adding this near the top of the macro to make Excel automatically choose "yes" or 'ok" for any messages that might have appeared:

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Import Web Data VBA "sometimes working"

    Hey JB. I actually tried that as well....No luck. I think I need a loop to keep trying the URL link. Maybe some code that will keep trying the code until there's no error. The website itself will work usually around 10x refershes. Can we add some code that will do this?

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Import Web Data VBA "sometimes working"

    Yeah, you could add something like:

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Import Web Data VBA "sometimes working"

    Hey JB,

    Thanks for getting back to me about this! I tried inserting your piece of code and it isn't taking the error into account. It will error out just after trying to import the first time. Thoughts? Please see below for the code that is in a module:

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Import Web Data VBA "sometimes working"

    Could it maybe be that the website takes time to load? A shot in the dark but maybe try:

    Please Login or Register  to view this content.
    with xml or IE, we usually tell it loop until the webpage is loaded. That may be the culprit here.

    abousetta
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  7. #7
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Import Web Data VBA "sometimes working"

    Hey abousetta,

    I tried your response:

    Please Login or Register  to view this content.
    However, it still errored out. The link that I am going to is XML. What code do I need to tell it to loop until the webpage is loaded? I think you are correct as I also believe that is the culprit.

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Import Web Data VBA "sometimes working"

    Please Login or Register  to view this content.
    This assumes that you have an xml object named xml.

    abousetta

  9. #9
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Import Web Data VBA "sometimes working"

    where do I put that in relation to my code?

  10. #10
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Import Web Data VBA "sometimes working"

    That would be used in conjunction with an xml object. So you would be telling the vba code to loop until the object heard back from the website. Now re-reading your last post, since the website is sending you back xml then you are better off using an xml object rather than the query table to get the information.

    abousetta

+ 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