VBA - Go To Website And Download File From Save Prompt
May 24, 2013
How to save a file onto the computer using VBA. The code template below that I found on another forum seems promising, except when I go to the desktop to access it, the .csv file has what looks like the page's source code instead of the actual file I want. This may be because when I go to the url, it doesn't automatically download the file; rather, I am asked to save the file to a certain location (since I don't know the path name of the uploaded file on the site).
Is there any way to alter this code to accommodate this, or will I have to use a different code entirely?
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object
I am trying to open a website, then for excel to download the csv file, then for it to save it in a specific folder under a specific name and file format (excel).
I am successful at opening the website with the following code, but how to do the rest.
Sub Searchez() Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") IE.Navigate "http://quote.morningstar.ca/Quicktakes/stock/keyratios.aspx?t=clwr®ion=USA&culture=en-CA&ops=clear" 'load web page google.com IE.Visible = True While IE.Busy DoEvents Wend
how can i use VBA tp download a file from a webpage? I've found the following that would display the source code of a webpage. I need to download a zip file and save it to the desktop.What alterations do I have to make?
Sub Downloadfile() Dim objHttp As Object Set objHttp = CreateObject("MSXML2.ServerXMLHTTP") Call objHttp.Open("GET", "http:\yahoo.com", False) Call objHttp.Send("") Call MsgBox(objHttp.ResponseText) End Sub
I have a program operating in excel 2007 that extracts a picture from a URL and puts it into a PPT slide. I now discover that PPT 2007 doesn't allow this.
So my intent now is to download the jpg into a local file and then import into the PPT.
This is from a couple of sites: [url] [url]
At the top of the code:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _ (ByVal pCaller As Long, _ ByVal szURL As String, _ ByVal szFileName As String, _ ByVal dwReserved As Long, _ ByVal lpfnCB As Long) As Long
in the excel cell if a URL picture needs to be inserted it starts with the prefix "picture=" then the http address.
This did not work.
So I then copied the code from the websites into a module (changing the destination file and URL to mine of course) and called the procedure and still nothing.
For a sheet that many non-expert users will use on different systems I need a macro that let's them save, print and send the results of their work. So I made a macro that makes a copy of only 1 sheet of the workbook and saves it with a given name to a given location. The problem is that I want a location prompt to ask the user where they want the file saved, while giving/suggesting them a fixed filename. A lot of different users will make and use their sheets so I need a certain naming policy to manage all the files. (date, location, etc)
I have a requirement to download a lot of historical data files from the archieve of an website. The url goes something like this: [URL]....
This downloads file for 21022014 ie. 21-Feb-2014. I need to be able to have a facility to have a selection criteria on my user form (in excel) where I specify a date range and the macro automatically downloads all the valid excel files available within that date range (files for Saturday, Sunday and some holiday dates will not be available in the website archive database) one after the other (like at single clcik of button) into a specific location (predefined viz.. c:/Users/EOD files/) on my laptop. Best would be if I am able to select the save location run time by using a 'Browse' like feature where I go and choose my local laptop folder...same type when we try uploading a file from our laptop to the web..
Currently I have information that includes numerous distributors information on one sheet. The code below separates each distributors information into a new tab and a new workbook, names the workbook and saves it in the specified file path.
I am trying to figure out a way to use an InputBox to popup and ask the user where all the new workbooks will be saved at. Thus, avoiding the need to change the code each time you want the new workbooks saved in a different folder .....
I have been working on automating IE. Part of my task involves using explorer to download a file from a given url and save it to disk. I've figured out how to launch explorer and start the download, but then a dialogue box appears asking whether to save the file and where to save it. how do I automatically get past this and save the file to e.g "quotes.xls"?
I have a spreadsheet that has hyperlinks in it and is mostly protected to prevent changes. Is there a way to prevent the "save changes" dialog box from appearing when this file is closed as I have to make this file available to others and don't want them to get this message or make save any changes.
I have the following code that I want to download everyfile at the listed ftp site to a folder on my computer. I was thinking about trying to make a key with dates in thisworkbook sheet1 starting in cell A1 and have it loop through.
Code: Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Save my workbook Then Open the SaveAs box with the path already pointing to a specific directory and with the Name and file format already entered (.xls)
This is basically to save time navigating through our folder structure (which is a real mess). I don't want to automatically saveas the file as the target folder will change each month and the last part of the file name will chance (month). So I'd like a bit of flexibility rather than total automation.
I am setting up a "save as" macro that saves a file by replacing another file in a folder. Even though the macro has been recorded by approving the replacement (the prompt appears "the file --- already exists. Do you want to replace the existing file?"), when I run the macro, I am again prompted about replacing the file. Is it possible to avoid the prompt so the file is automatically saved by replacing the named file?
I have an excel file which contains 9 columns. Column A contains an article number i.e 12345 . Column B contains name of the product. Columns C and D contain Description and Specifications respectively. Columns E,F,G,H and I contain URL:s of images.
I want to do following.
1. Download all the images in a folder on my harddisk.
2. Copy the text in column C and place it under the text in column D.
complete the attached code (Excel VBA) to automatically process a File Download dialog from Internet Explorer. I want to click "Save" which will produce the "Save As" dialog. Then I need to enter a default filename like (C:Temp) and click "Save" again. When this is working, I will hide Internet Explorer to make the operation completely transparent to the user. The URL is a sample chosen specifically for this test case.
Public Sub Report_Test()
Dim objIE As SHDocVw.InternetExplorer Dim strURL As String Dim varItem As Variant
' Establish connection to the Internet Explorer application. Set objIE = CreateObject("InternetExplorer.Application")
' Set Internet Explorer visible. objIE.Visible = True
I've recorded this code and am looking to include it in a button. I would like for when a user clicks the button assinged macro that the active sheet is cloned and saved as a CSV file. The user should be prompted before saving on where (file location) they'd like to save the file.
Sub CloneWorksheet() ' ' CloneWorksheet Macro ' ' Sheets("SDW&Customer Workshop scheduled").Select Sheets("SDW&Customer Workshop scheduled").Copy ActiveWorkbook.SaveAs Filename:= _ "C:Documents and Settings1167916My DocumentsTestBook1.csv", FileFormat:= _ xlCSV, CreateBackup:=False End Sub
I'm trying to download an Excel file from the internet and then extract data out of it. The problem is that I don't get any errors, yet the file downloaded is only 1kb in size. The extraction bit works, but the file is empty. The actual file is size 350KB.
Code: Sub ExtractDataTest()
Dim FileNum As Long Dim FileData() As Byte Dim MyFile As String Dim WHTTP As Object