Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50158

Compile Error - Importing multiple CSV files via GetOpenFilename

$
0
0
When I click a button in a userform i want it to import the following CSV files which will always have the same column format (the with part was recorded and then modified to operate on the files selected)

Please help thank you it doesn't get far

Private Sub CommandButton1_Click()
Dim X As Variant

'Opens the dialog
X = Application.GetOpenFilename("CSV Files (*.csv),*.csv,Text Files (*.txt),*.txt", 4, "Select Files", , True)



'Loops through every file that is selected and opens each one
For Y = 1 To UBound(X)

With ActiveSheet.QueryTables.Add(Connection:= _
"X(Y)", Destination _
:=Range("1,(Y+(Y-1))"))
.Name = "X(Y)"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlMacintosh
.TextFileStartRow = 2
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = True
.TextFileOtherDelimiter = """"
.TextFileColumnDataTypes = Array(9, 5, 9, 1, 9, 9)
.Refresh BackgroundQuery:=False
.UseListObject = False
End With

Next Y

End Sub

Viewing all articles
Browse latest Browse all 50158

Trending Articles