Saltar al contenido

Macro que cargar archivos .txt en hoja resumen

publicado

Buenas super genios del blog.

Soy bastante novato en las macros pero al mismo tiempo soy muy travieso con ellas lo cual me ha dado excelentes resultados laborales y personales.

Bueno mi duda es como hacer que esta macro que me funciona genial ( y encontrada en un foro, solo que le hice leves modificaciones), me cargue el archivo .txt que se llama igual a lo concatenado en un especifica celda (O1) y no solo el libro que esta indicado en la macro, como lo hago dinámico a mi celda O1 y no a estar poniendo la dirección del archivo en la macro manualmente.

adjunto macro.


Sub Cargar_Resumen()


Ubica = Range("K1")


With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;[B]C:\Users\lesth_000\Desktop\NOMINA\Nomina Bodega 25092013.txt[/B]", Destination:=Range(Ubica))
[COLOR=#008000]'cambiar esta direccion por la que se concatena en la celda O1'[/COLOR]

.Name = "Nomina Bodega 25092013._1"
.FieldNames = True
.RowNumbers = True
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(2, 18, 2, 11, 18, 2, 11, 2, 50)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With


End Sub


[/CODE]

De antemano gracias!

[color=blue]- - - - - Mensaje combinado - - - - -[/color]

Ademas los .txt estan en la misma carpeta del libro de excel!! saludos

Featured Replies

publicado

Pura vida lestherchaga

Si te entendí bien prueba esta modificación:

Sub Cargar_Resumen()Ubica = Range("K1")
pach = ActiveWorkbook.Path


With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & pach & "\" & [O2] & ".txt", Destination:=Range(Ubica))
'cambiar esta direccion por la que se concatena en la celda O1'


.Name = "Nomina Bodega 25092013._1"
.FieldNames = True
.RowNumbers = True
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = False
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1252
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(2, 18, 2, 11, 18, 2, 11, 2, 50)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With


End Sub[/CODE]

Salu2

Archivado

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