+ Reply to Thread
Results 1 to 8 of 8

downloading file from Web

  1. #1
    Registered User
    Join Date
    02-06-2009
    Location
    kodai
    MS-Off Ver
    Excel 2003
    Posts
    12

    downloading file from Web

    I need to download a file from web using excel vba.

    I have written code everything works fine.

    When I run the code, a pop-up from IE asks for
    saving/viewing/cancelling the downloading.

    I need to download the file automatically
    to a specified location avoiding (preventing)
    the popup message.

    Kindly help

  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,258

    Re: downloading file from Web

    Hello headhair,

    This API routine will download any type of file from the web and save it where you like. There is an example macro to download the Google logo to the "C" drive.
    Please Login or Register  to view this content.
    Example Download Macro
    Please Login or Register  to view this content.

    Adding the Macro
    1. Copy the macro above pressing the keys CTRL+C
    2. Open your workbook
    3. Press the keys ALT+F11 to open the Visual Basic Editor
    4. Press the keys ALT+I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Paste the code by pressing the keys CTRL+V
    7. Make any custom changes to the macro if needed at this time.
    8. Save the Macro by pressing the keys CTRL+S
    9. Press the keys ALT+Q to exit the Editor, and return to Excel.

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    Last edited by Vaibhav; 04-14-2012 at 09:49 PM.
    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
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: downloading file from Web

    You didn't specify what kind of file.

    Maybe this is the simplest method:
    Make sure the reference to Microsoft XML v 3.0 is active.

    Please Login or Register  to view this content.



  4. #4
    Registered User
    Join Date
    02-06-2009
    Location
    kodai
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: downloading file from Web

    Thanks for the reply.

    1) I need to login a website
    2) Download a file Not having direct link

    I wrote code as below
    Private Sub CommandButton1_Click()


    ' Prepare to open the web page
    Set ie = CreateObject("InternetExplorer.Application")


    With ie
    .Visible = True
    .Navigate "http://218.248.72.237/BSNL/"

    ' Loop until the page is fully loaded
    Do Until Not .Busy
    DoEvents
    Loop


    'Login to the website
    Set ipf = ie.document.all.Item("txtUserName")
    ipf.Value = Trim(ActiveSheet.Range("H4").Value)
    Set ipf = ie.document.all.Item("txtUserPass")
    ipf.Value = ActiveSheet.Range("H5").Value
    Set ipf = ie.document.all.Item("Submit")
    ipf.Value = "Enter"
    ipf.Click

    ' Loop until the page is fully loaded
    Do Until Not .Busy
    DoEvents
    Loop


    ' Downloading the file
    .Navigate "http://218.248.72.237/BSNL/OPERATOR/home/LKLexportExcel.asp?mode=excel"



    ' Close the internet explorer application
    ie.Quit
    end with

    End Sub
    The code is working fine, except that
    I am prompted by IE to save the file.

    I just wanted to remove the "Save as" prompt by IE.

    Thanks again.

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

    Re: downloading file from Web

    Hello headhair,

    The code I added to your should work. If not let me know.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    02-06-2009
    Location
    kodai
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: downloading file from Web

    Thanks Leith Ross

    It returns an error

    Automation Error
    Trying to revoke a drop target that has not been registered

    Actually the part of the Code:
    ' Downloading the file
    .Navigate "http://218.248.72.237/BSNL/OPERATOR/home/LKLexportExcel.asp?mode=excel"
    downloads an Excel (.xls) file

    I wonder, in which location the downloaded file will be saved?

  7. #7
    Registered User
    Join Date
    01-02-2014
    Location
    bangalore
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: downloading file from Web

    Hi Leith,

    I tried to run ur code but it gave me error saying "Run time error - 2147221248(80040100) Method 'ExecWB' of object 'IWebBrowser2' failed.

    Can u help me out with this

  8. #8
    Registered User
    Join Date
    04-01-2014
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: downloading file from Web

    Hi

    Even i am facing same problem for URLDownloadfile function

    Run time error - 2147221248(80040100

    Kindly help urgently

    I am using MSoffice 2007 and Windows 7

+ 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