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
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