download .csv file from web

sal21

Active Member
Joined
Apr 1, 2002
Messages
291

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.
Hi.
I read only today your request, so probably it's late.
Anyway, I don't have a complete solution but I think you can workaround to find the solution starting from this code.
VBA Code:
Dim URL As String
Dim dat1 As Long, dat2 As Long

URL = ActiveSheet.Cells(2, 2)

Dim Dir_csv As String
Dir_csv = "C:\Temp\fileOut.csv" to change with yours

Dim WinHttpReq As Object
Dim objStream As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", URL, False
WinHttpReq.send

If WinHttpReq.Status = 200 Then
    Set objStream= CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = 1
    objStream.Write WinHttpReq.responseBody
    objStream.SaveToFile Dir_csv, 2
    objStream.Close
    
Else
    MsgBox (WinHttpReq.Status & " : Not found")
End If
I tried quickly and the resulting .csv is not as "clean" as necessary. But, probably, you can arrange it properly.
Hope this could help you.
 
Upvote 0
Hi.
I read only today your request, so probably it's late.
Anyway, I don't have a complete solution but I think you can workaround to find the solution starting from this code.
VBA Code:
Dim URL As String
Dim dat1 As Long, dat2 As Long

URL = ActiveSheet.Cells(2, 2)

Dim Dir_csv As String
Dir_csv = "C:\Temp\fileOut.csv" to change with yours

Dim WinHttpReq As Object
Dim objStream As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", URL, False
WinHttpReq.send

If WinHttpReq.Status = 200 Then
    Set objStream= CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = 1
    objStream.Write WinHttpReq.responseBody
    objStream.SaveToFile Dir_csv, 2
    objStream.Close
   
Else
    MsgBox (WinHttpReq.Status & " : Not found")
End If
I tried quickly and the resulting .csv is not as "clean" as necessary. But, probably, you can arrange it properly.
Hope this could help you.

tsk bro the code work, perfect!
 
Upvote 0
Hi.
I read only today your request, so probably it's late.
Anyway, I don't have a complete solution but I think you can workaround to find the solution starting from this code.
VBA Code:
Dim URL As String
Dim dat1 As Long, dat2 As Long

URL = ActiveSheet.Cells(2, 2)

Dim Dir_csv As String
Dir_csv = "C:\Temp\fileOut.csv" to change with yours

Dim WinHttpReq As Object
Dim objStream As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", URL, False
WinHttpReq.send

If WinHttpReq.Status = 200 Then
    Set objStream= CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = 1
    objStream.Write WinHttpReq.responseBody
    objStream.SaveToFile Dir_csv, 2
    objStream.Close
   
Else
    MsgBox (WinHttpReq.Status & " : Not found")
End If
I tried quickly and the resulting .csv is not as "clean" as necessary. But, probably, you can arrange it properly.
Hope this could help you.
Hello, please allow me to post in another article. Can you help me with a piece of code used to download an excel file (.xls) from "Đơn vị hành chính"
to the workstation. Thank you.
 

Attachments

  • 1.jpg
    1.jpg
    183.9 KB · Views: 5
Upvote 0

Forum statistics

Threads
1,215,145
Messages
6,123,289
Members
449,094
Latest member
GoToLeep

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