Macro para importar datos en formato de texto

Buenas noches,

Necesito importar datos a un archivo de Excel desde archivos de datos con extensión .ASC, grabo la macro manualmente, uso la herramienta "Obtener datos externos", el programa pide "Texto en columnas" y selecciono "|", abre y funciona manualmente sin problemas. Pero cuando voy a ejecutar la macro recién grabada reporta un error en el siguiente comando: .CommandType = 0

Esta es la macro que se grabó:

Sub Macro2()
    Range("A1").Select
    With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Users\Documentos\xxxxxx.asc" _
        , Destination:=Range("$A$1"))
        .CommandType = 0
        .Name = "117239_502"
        .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 = False
        .TextFileCommaDelimiter = False
        .TextFileSpaceDelimiter = False
        .TextFileOtherDelimiter = "|"
        .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False
    End With
End Sub

Espero su respuesta.

1 Respuesta

Respuesta
1

Borra esa línea

.CommandType = 0

Prueba nuevamente y me comentas.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas