Saltar al contenido

Macro para abrir excel csv delimitado por puntos y comas.

publicado

Buenas chicos tengo el siguiente problemilla.

Mediante una macro intento acceder a un archivo csv. delimtado con puntos y comas. y al usar  Workbooks.Open Filename:="C:\Users\pc\Desktop\stock.csv"   me la abre mal 

image.thumb.png.56ac083838636e720c1d24b3a2aea015.png

 

Si la abro normal me la abre perfectamente, he intentado un par de cosillas pero nada fracaso total. Si podéis arrojarme un poco de luz sobre esto os lo agradecería mucho.

Un saludo.

 

 

 

Featured Replies

  • 4 months later...
publicado
  • Autor

Doy solución al problema que propuse.

 

  ActiveWorkbook.Queries.Add Name:="stock", Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Origen = Csv.Document(File.Contents("UBICACION DEL ARCHIVO""),[Delimiter="";"", Columns=15, Encoding=1252, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & "    #""Encabezados promovidos"" = Table.PromoteHeaders(Origen, [PromoteAllScalars=true])," & Chr(13) & "" & Chr(10) & "    #""Tipo cambiado"" = Table.TransformColumnTypes(#""Encabezados promovidos"",{{""Almacén"", Int64.Type}, " & _
        "{""Artículo"", Int64.Type}, {""Denominación"", type text}, {""Fecha Congelado"", type date}, {""Fecha Caducidad"", type date}, {""Lote"", type text}, {""SSCC"", type text}, {""SSCC Superior"", type text}, {""Peso Bruto"", type number}, {""Tara EDTR"", type number}, {""Peso Neto"", type number}, {""Unidades"", type number}, {""Proveedor"", type text}, {""Nombre Prov." & _
        """, type text}, {""Nº Pedido"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Tipo cambiado"""

    Sheets.Add After:=ActiveSheet

    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=stock;Extended Properties=""""" _
        , Destination:=Range("$A$1")).QueryTable

        .CommandType = xlCmdSql

        .CommandText = Array("SELECT * FROM [stock]")

        .RowNumbers = False

        .FillAdjacentFormulas = False

        .PreserveFormatting = True

        .RefreshOnFileOpen = False

        .BackgroundQuery = True

        .RefreshStyle = xlInsertDeleteCells

        .SavePassword = False

        .SaveData = True

        .AdjustColumnWidth = True

        .RefreshPeriod = 0

        .PreserveColumnInfo = False

        .ListObject.DisplayName = "stock"

        .Refresh BackgroundQuery:=False

    End With
 

 

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.