VBA URL save the csv file to folder location

JJCA99

Board Regular
Joined
Dec 4, 2014
Messages
50
Hello all,

i've read through many codes and none seem to be working for the URL or the csv file i'm trying to save.


The below code didn't save the file with my data looked like the below pic.

Capture.PNG



One code I've used:
VBA Code:
Option Explicit

Private Declare PtrSafe Function URLDownloadtoFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As LongPtr, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As LongPtr, _
ByVal lpfnCB As LongPtr) As LongPtr

Sub SFDC_Rpt()

Dim FileURL As String
Dim SFilename As String


FileURL = "https://example.com/123q2341324ddEf?view=d&snip&export=1&enc=UTF-8&xf=csv"
SFilename = "C:\URLTest\Test.csv"

URLDownloadtoFile 0, FileURL, SFilename, 0, 0

End Sub

Any help on why I can't save my file would be greatly appreciated.

JF
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
If your URL is that of an actual CSV, your code looks like it will work, albeit not structured for 32-bit pre-Excel 2010. The URL you supplied is just a web page, so you got the source code as the contents.
 
Upvote 0
If your URL is that of an actual CSV, your code looks like it will work, albeit not structured for 32-bit pre-Excel 2010. The URL you supplied is just a web page, so you got the source code as the contents.

Hey Zack i'm not sure I follow on how to fix that? I have the hyperlink to the URL in my workbook and when I click on it it downloads the file but I can't seem to get the macro to download and open the file.
 
Upvote 0

Forum statistics

Threads
1,215,781
Messages
6,126,870
Members
449,345
Latest member
CharlieDP

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top