get csv from remote CE computer

Vilas Desai

New Member
Joined
Jan 28, 2011
Messages
4
Sub GetCSV()
Const strFilename = "MINUTE.csv"
Dim wshList As Worksheet
Dim wshTarget As Worksheet
Dim r As Long
Dim m As Long
Dim objXML As Object
Dim f As Long
Dim arrResp() As Byte
Dim strWebfile As String
Dim strLocalFile As String
Dim strIP As String
Dim i As Long
strLocalFile = "C:\Temp\" & strFilename
' Create XMLHTTP object
Set objXML = CreateObject("MSXML2.XMLHTTP")
' List op IP addresses
Set wshList = Worksheets("IPList")
m = wshList.Range("A" & wshList.Rows.Count).End(xlUp).Row
' Loop through IP addresses
For r = 2 To 2
strIP = wshList.Range("A" & r).Value
' Target sheet
Set wshTarget = Worksheets(strIP)
wshTarget.Cells.ClearContents
' Address of CSV file on web
strWebfile = "http://" & strIP & "/" & strFilename
' Send request
objXML.Open "GET", strWebfile, False
objXML.Send
' Wait
i = 0
Do While objXML.ReadyState <> 4 And i < 100
DoEvents
i = i + 1
Loop
If objXML.ReadyState <> 4 Then
wshTarget.Range("A1").Value = "Not available"
Else
' Get data into byte array
arrResp = objXML.ResponseBody
' Create new file
f = FreeFile
Open strLocalFile For Binary As #f
' Write data
Put #f, , arrResp
' Close file
Close #f
' Code to read local file into the appropriate sheet
With wshTarget.QueryTables.Add(Connection:="TEXT;" & strLocalFile, _
Destination:=wshTarget.Range("A1"))
.SaveData = True
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh
End With
' Delete the file
Kill strLocalFile
End If
Next r
' Release memory
Set objXML = Nothing
End Sub

I have a excel 2007 VBA macro that is intended to pick up a same named .csv file from several devices each with unique IP and places it in a computer at a protected location. for ex. c://temp/myfile.csv When I run the below code in a standard module, I get the error: Code Error No "2146697208 (800c0008) The download of the specified resource has failed" and when I debug, the error points to (yellow highlighted) the line 30 objXML. Sendobjxml.send0 the error at limneth The Th
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,944
Messages
6,122,384
Members
449,080
Latest member
Armadillos

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