I'm trying to import a text file into excel through the following macro:
Sub Teste()
Dim intervalo As String
intervalo = "intervalo"
Workbooks.Add
ActiveWorkbook.Sheets("Plan1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Desktop\ArquivoCSV.csv", Destination:= _
Range("$A$1"))
.CommandType = 1
.Name = intervalo
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 4, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Range("intervalo").Select
ActiveWorkbook.SaveAs Filename:="testeCSV"
ActiveWorkbook.Close
End Sub
But when debugging, when I get to .CommandType = 1
, an error occurs and I can not identify the problem.