get csv from remote CE computer

Vilas Desai

New Member
Jan 28, 2011
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)
' Address of CSV file on web
strWebfile = "http://" & strIP & "/" & strFilename
' Send request
objXML.Open "GET", strWebfile, False
' Wait
i = 0
Do While objXML.ReadyState <> 4 And i < 100
i = i + 1
If objXML.ReadyState <> 4 Then
wshTarget.Range("A1").Value = "Not available"
' 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, _
.SaveData = True
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
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

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...