justdriving
09-15-2011, 12:20 PM
I was trying to use this program to import multiple csv files into a Sheet1 one-after-another.
Private Sub Workbook_Open()
With ActiveSheet.QueryTables.Add(Connection:= "TEXT;C:\1.csv", Destination:=Range("B1"))
.Name = "1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Sheet1").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
End Sub
I also wanted to ensure that as soon as 1.csv is imported. It can import A.csv and 99.csv files. I have no idea how to do that?
In Col A, I want to write 1, A and 99 (respective file names) to every cells(row_n, 1).
Private Sub Workbook_Open()
With ActiveSheet.QueryTables.Add(Connection:= "TEXT;C:\1.csv", Destination:=Range("B1"))
.Name = "1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Sheets("Sheet1").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
End Sub
I also wanted to ensure that as soon as 1.csv is imported. It can import A.csv and 99.csv files. I have no idea how to do that?
In Col A, I want to write 1, A and 99 (respective file names) to every cells(row_n, 1).