I have a web service that produces a large amount of CSV data, which I need to import into excel 2013.
I have found the straightforward way to do this:
With ActiveSheet.QueryTables.Add(Connection:="TEXT;" & URL, Destination:=Cells(1, 1))
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.WebPreFormattedTextToColumns = True
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
.WorkbookConnection.Delete
End With
However, I also need to send the web service a payload with parameters in order to filter the data it returns.
The only way I have found of doing this is to use the .PostText property, but this requires the connection to be "URL;" rather than "TEXT;" and therefore doesn't allow the .TextFileCommaDelimiter property, which is critical to the output in the worksheet.
Is there a straightforward way to solve this - i.e. extract the data from a web service, using post data, but also ensure excel correctly interprets the comma delimited format?
Are you able to change the format provided by the web service?
I have returned data in HTML form (
<table>...</table>
) to then do what you need - i.e. useConnection:"URL"
.The data is then auto-formatted based on the HTML table tags into an Excel sheet.