Macro: Abrir archivos txt y filtrar la información de cada archivo (txt) en un solo archivo de excel

Tengo el siguiente dilema y no sé si una macro me facilitaría dicha operación: en una carpeta tengo unos archivos txt, la idea es que la macro abra cada archivo y me filtre la información, así como lo ilustran las gráficas: No se si con expresiones regulares sea posible.

Salida archivo en excel: es decir, de los archivos de texto traer los campos: Caracteres antes del símbolo ># (nombre equipo), slot y serial-no

Un archivo de texto sería así:

??????"??-??
USTED DEBE ESTAR AUTORIZADO PARA INGRESAR A ESTA MAQUINA***CUALQUIER USO NO AUTORIZADO SERA MONITOREADO, REGISTRADO Y DESCONECTADO***USTED SERA EL UNICO RESPONSABLE POR MAL MANEJO Y/O DAnOS OCASIONADOS*******MZL-AUT-03301-7302-I-A********
login: prg
password: 
Welcome to ISAM
last login : 29/06/17 16:37:29
MDE-NAR-08701-7302-I-A>#show equipment slot detail
================================================================================
slot table (detailed)
================================================================================
-\ 
--------------------------------------------------------------------------------
Slot
--------------------------------------------------------------------------------
                  Slot : nt-a planned-type : nant-a 
           Actual-type : nant-a oper-status : enabled 
          Error-status : no-error 
          Availability : available 
             Serial-no : AA0999EB328 
           Failed-test : 00:00:00:00 
 dual-host-loc : none 
--------------------------------------------------------------------------------
Slot
--------------------------------------------------------------------------------
                  slot : lt:1/1/1                     planned-type : not-planned   
           Actual-type : empty oper-status : disabled 
          Error-status : no-error 
             Serial-no : AAA81213AB2 
           Failed-test : 00:00:00:00 
 lt-restart-time : 1970-01-01:00:00:00 
 dual-host-loc : none 
--------------------------------------------------------------------------------
Slot

No se si sea posible, o que idea me recomiendan, para optimizar.

2 Respuestas

Respuesta
2

Para ver cómo está la información en el txt y cómo quieres la carga. Envíame un par de archivos txt y un archivo de excel con la carga de los datos de esos 2 archivos txt.

Mi correo [email protected]

En el asunto del correo escribe tu nombre de usuario “Leonardo Ortiz Restrepo

Te anexo la macro

Sub Cargar_Txt()
'
' Por. Dante Amor
'
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set l1 = ThisWorkbook
    Set h1 = l1.Sheets(1)
    h1.Rows("2:" & Rows.Count).Clear
    ruta = l1.Path & "\"
    arch = Dir(ruta & "*.txt")
    j = 2
    Do While arch <> ""
        Workbooks.OpenText Filename:=ruta & arch, _
            Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, _
            TextQualifier:=xlNone, ConsecutiveDelimiter:=False, _
            Tab:=False, Semicolon:=False, Comma:=False, Space:=False, _
            Other:=False, FieldInfo:=Array(1, 1), TrailingMinusNumbers:=True
        Set l2 = ActiveWorkbook
        Set h2 = l2.Sheets(1)
        Set b = h2.Cells.Find(">#", LookAt:=xlPart)
        If Not b Is Nothing Then
            equipos = Split(b.Value, ">#")
            eq = equipos(0)
            Set r = h2.Cells
            Set b = r.Find("slot :", LookAt:=xlPart)
            If Not b Is Nothing Then
                celda = b.Address
                Do
                    'detalle
                    slots = Split(b.Value, "slot : ")
                    datos = Split(slots(1), " ")
                    slot = datos(0)
                    seriales = Split(b.Offset(12, 0), ":")
                    serial = WorksheetFunction.Trim(seriales(1))
                    h1.Cells(j, "A") = eq
                    h1.Cells(j, "B") = slot
                    h1.Cells(j, "C") = serial
                    j = j + 1
                    Set b = r.FindNext(b)
                Loop While Not b Is Nothing And b.Address <> celda
            End If
        End If
        l2.Close False
        arch = Dir()
    Loop
    Application.ScreenUpdating = True
    MsgBox "Fin"
End Sub

sal u dos

Respuesta
1

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas