+ Reply to Thread
Results 1 to 7 of 7

Macro to handle download prompt

  1. #1
    Registered User
    Join Date
    08-07-2012
    Location
    Limerick,Ireland
    MS-Off Ver
    Excel 2010
    Posts
    10

    Macro to handle download prompt

    Hi, I'd need to download a file from a website.
    It involves adding a lot of information on a website in textboxes and then clicking a submit button.
    My problem is, that a download prompt comes up on the screen and I don't know how to handle it with my macro.
    I've seen various posts with the same problem, and they usually try with sendkeys. I did too.
    However most of the stuff is vbscript.
    How do I send keys in a macro.
    I tried the following:

    Please Login or Register  to view this content.
    The result was the given text, so next I tried to send just the arrows

    Please Login or Register  to view this content.
    Now this macro didn't do anything, when I ran it. Even though I was expecting the activecell to move three cells to the left.
    Not only that, but I actually had to stop the macro because for whatever reason it was running for minutes!!!!!!
    IN an extreme case this should be dealt with in 4 seconds, but I waited more than a minute and this exact macro still wasn't done.

    I tried to modify it:

    Please Login or Register  to view this content.
    This didn't work either and it was stuck running like before

    I tried this version, but it didn't compile in the first place:
    Please Login or Register  to view this content.
    So can anyone tell me, how to send the left arrow key in a vba macro?

    Even better can someone tell me, how to answer a download prompt for saving an excel file?
    Some people could actually make the sendkeys work for them, and the active window was the download prompt but the sendkeys would still not send the keys to that active window of the prompt!
    I tackled all the hard part of pulling information from a website, and Now I'm stuck at the finish line, because I can't handle the download prompt!!!
    Please help!
    Last edited by Captainplanet; 11-10-2012 at 10:42 AM.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Macro to handle download prompt

    Have you tried:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    08-07-2012
    Location
    Limerick,Ireland
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to handle download prompt

    Ok, I think I figured out my problem!
    Here's what i messed up:
    what I used:
    Please Login or Register  to view this content.
    what I shoud've used
    Please Login or Register  to view this content.
    anyway, thanks, the thing works now!
    I'll post again if it could handle the download prompt this way!
    Last edited by Captainplanet; 11-10-2012 at 10:41 AM.

  4. #4
    Registered User
    Join Date
    08-07-2012
    Location
    Limerick,Ireland
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to handle download prompt

    Sry!
    I'll make sure to avoid that in the future!

    Anyway,
    I have the code finished now and the sendkeys doesn't really affect the download prompt. It takes quite a while until the download prompt actually pops up, so I did the following:

    after the submit button has been pushed I had this line of code

    Please Login or Register  to view this content.
    This didn't work, so I separated the latter part of the code with the sendkeys method

    so the original code ended like this:
    Please Login or Register  to view this content.
    and there was the separate macro:

    Please Login or Register  to view this content.
    This actually triggered behind the donwload prompt. After the download window was on my screen for a while(went to get a coffee) I pushed manually to save, and between the next window loading to choose a location I caught a glimpse of my messagebox waiting to be OK'd. So I thought maybe the messagebox stopped it from running, so I removed the messagebox, but the result is the same, from which I can only deduce that the sendkeys lines don't send the keys to the activewindow, but the window where the macro was started aka. the excel sheet with the embedded browser.

    So the question remains:
    Does anyone know how to handle a download prompt with a VBA macro?

  5. #5
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Macro to handle download prompt

    It's covered pretty comprehensively here: http://www.siddharthrout.com/2011/10...wnload-window/ and here: http://www.siddharthrout.com/2012/02...indow-part-ii/

    That said, my preference would always be to exclude IE altogether, it's usually not necessary and is very slow

  6. #6
    Registered User
    Join Date
    08-07-2012
    Location
    Limerick,Ireland
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Macro to handle download prompt

    Kyle,
    That is an amazing resource! This helps a lot!
    Cannot thank you enough!

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

    Re: Macro to handle download prompt

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    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.

+ 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