I would like to automate the importing of a csv file.
The naming convention of the csv files is “filename_yyyymmdd.csv”
I would like the user to be able to choose which file to import although the default would be set to the current date.
My code below doesn’t return any data. Can anyone help with a solution.
Thanks
Dim DownloadCsv
‘ Clear existing data
Cells.Select
Selection.ClearContents
Range(“A1”).Select
DownloadCsv = InputBox(“Please enter the date of the ‘Daily Sales’ report that you wish to view (yyyymmdd)”, “CSV Download”, Format(Date, “yyyymmdd”))
With ActiveSheet.QueryTables.Add(Connection:= _
“TEXT;Z:Daily_Sales_” & DownloadCsv & “20060827.csv”, Destination:=Range(“A1”))
.FieldNames = True
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileCommaDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
End With
Range(“A1”).Select
End Sub