Skip to main content
1 de 2
LucasMotta
  • 1mil
  • 1
  • 10
  • 34

Problema ao importar arquivo texto via VBA

Estou tentando importar um arquivo texto para o excel através da seguinte 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

Porem quando debugando, ao chegar no .CommandType = 1 acontece um erro e não estou conseguindo identificar qual o problema.

LucasMotta
  • 1mil
  • 1
  • 10
  • 34