PDA

View Full Version : Solved: import csv from the web



sandbagger
10-13-2008, 07:55 PM
i am trying to import a .csv file linked from a website. i can get it imported into excel but i can't figure out how to tell excel to import it as a delimited file.

my code below imports each row into one big cell like this:
"aaa,bbb,ccc"
i want it imported such that "aaa","bbb", and "ccc" are in adjacent cells

i know when importing a local csv file you can set
.TextFileCommaDelimiter = True
and am after something like that.



Dim url As String
url = "URL;http://www.investis.com/chartsource/csvdownload.csv?symbol=UBS.N&startday=14&startmonth=10&startyear=2007&endday=14&endmonth=10&endyear=2008&btnSubmitCvs.x=41&btnSubmitCvs.y=5"
With ActiveSheet.QueryTables.Add(Connection:=url, Destination:=Range("I4"))
.Name = "test"
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = False
.WebSingleBlockTextImport = True
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With

sandbagger
10-14-2008, 07:37 PM
well the answer is just to import as text not url. the only problem now is that i need to suppress this progress window while the macro is running.

http://img80.imageshack.us/img80/8849/81236834el7.jpg

any ideas on how to do this?



url = "TEXT;http://www.investis.com/chartsource/csvdownload.csv?symbol=UBS.N&startday=14&startmonth=10&startyear=2007&endday=14&endmonth=10&endyear=2008&btnSubmitCvs.x=41&btnSubmitCvs.y=5"
With ActiveSheet.QueryTables.Add(Connection:=url, _
Destination:=Range("I4"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With

Kenneth Hobs
10-15-2008, 09:53 AM
DisplayAlerts:
Sub t()
Dim URL As String
URL = "TEXT;http://www.investis.com/chartsource/csvdownload.csv?symbol=UBS.N&startday=14&startmonth=10&startyear=2007&endday=14&endmonth=10&endyear=2008&btnSubmitCvs.x=41&btnSubmitCvs.y=5"
Application.DisplayAlerts = False
With ActiveSheet.QueryTables.Add(Connection:=URL, _
Destination:=Range("I4"))
.Name = "test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Application.DisplayAlerts = True
End Sub