Closed Thread
Results 1 to 2 of 2

Strange Macro Hang

  1. #1
    Registered User
    Join Date
    05-11-2009
    Location
    Dayton, OH
    MS-Off Ver
    Excel 2007
    Posts
    5

    Strange Macro Hang

    I have been struggling for a week or so trying to figure this out and I am having no luck so I am sending it out to you all in hopes of some help/advice.

    I have hobbled together a macro that downloads and analyzes stocks. To get the stocks historical prices I use the following code (borrowed from diytraders):
    Please Login or Register  to view this content.

    This code works fine...for a while then will hang and force me to close and restart on/around this line:
    Please Login or Register  to view this content.

    I have used Fiddler to monitor the traffic in and out of my computer so I know that it is sending the request properly and that the response in coming back on-time and in the correct format. This code typically hangs after 10-40 loops (one loop per stock) but isn't very consistent on where it decides to give up.

    I have previous versions of this code in earlier workbooks and they run just fine hundreds of times without fail. The main difference in the code now is that I have added a few subroutines to do more evaluations as well as checking other sheets (a fair amount of Selection.Find) and adding/subtracting data from them depending on the analysis.

    After a lot of google searching I have tried many things: Turned off screen updating... no luck, set most of my arrays and ranges to "Nothing" when not in use...no luck, deleted all connections to the workbook...no luck.

    Here is where things get very strange.

    As I stated earlier, previous version workbooks work just fine. If I have the problematic workbook open along with a previous version workbook I can run the macro on the previous version workbook and it will obviously run fine. Now, if I go ahead and run my macro on the problematic workbook it will now run flawlessly! So by running my previous workbook with the problem one open, something happens that allows the broken code to run, but only if a previous working version runs first. Keep in mind that the XMLHTTP code is not altered in any way in the problematic version, in fact the difference in the macros is only that code has been added. None of the original coding has been modified in any way.

    The second strange occurance is that if I run the code in debug mode with a breakpoint set anywhere (doesn't matter where), I can run the code by holding down F5 and the code will run through it's entirety flawlessly. This happens even if I have not run an older version beforehand.

    I am completely stumped here as to what is causing this un-ending hang. In the meantime I can run my code but having older workbooks open is not only a pain but a waste of resources, and holding down F5 just hurts my finger . So, has anyone experienced anything like this before? Is there something I that I could be missing that could be causing this issue? Any help/advice would be greatly appreciated!

    Thank you in advance!!!

    Robert
    Last edited by Zambo; 02-01-2010 at 06:56 PM.

  2. #2
    Forum Contributor
    Join Date
    07-13-2007
    Posts
    151

    Re: Strange Macro Hang

    I know your post is almost 3 months old, but I thought I'd respond anyhow since no one else has.

    I don't see a call to DeleteURLCacheEntry in this code snippet. Is it possible that by running the old version successfully, you're getting the results you want into cache and when you run the new version, it's using those results and that's why it completes? But when you just run the new version, you're somehow submitting URLs differently as a result of this additional code, and getting an error page along the way that does not offer a .responsebody?

    Not sure that makes sense. If the new version modified any of the variables in your URL construct, like EM, ED, EY, etc., you could end up submitting a URL that results in an error, but that doesn't explain why it works if run after the old version.

    I know you said you monitor the traffic and see the return response in a timely manner, but when it hangs, are you getting the response you wanted? Or an error page that does not have anything for the .responsebody property? Check the WebView tab in the response header section of Fiddler.

    Just throwing some thoughts out. I"m curious as to what you may have found. It's always good to learn something new.

Closed 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