MACRO TO FEED AN XLS FILE FROM N ARCHIVES

0

Macro to feed an xls file from several (the amount may vary) xls files contained in a specific directory.

The format is the following:

Source files: Contain a header and a single record below it. (A1: I2)

Destination file: Must contain the same header and store the data found in each source file (A2: I2).

Each time the macro is run you should clean the data in the destination file and get the data of all the files in a specific folder.

    
asked by Jimmy Bianco 08.01.2018 в 21:14
source

1 answer

0
Private Sub OpenAndSaveNuevoLibro(archivoOrigen As String, contador As Integer)
Dim LibroOrigen As Workbook, LibroDestino As Workbook, LibroOrigen2 As Workbook
Dim FileNm As String, sContador As String

 Set LibroOrigen = Workbooks.Open(archivoOrigen)
 Set LibroDestino = ThisWorkbook
 sContador = contador + 1

With LibroDestino
    LibroOrigen.Sheets("hoja1").Rows("2:2").Copy .Sheets("hoja1").Rows(sContador)
    .Save
    '.Close Savechanges:=False
End With

LibroOrigen.Close Savechanges:=False

End Sub

Sub ProcesarArchivos()
'1. Eliminar registros de Destino (desde fila 2, hasta el final)
'2. Recorrer los archivos de directorio de entrada
Call OpenAndSaveNuevoLibro("D:\RAIZ\in\entrada.xls", 1)
End Sub
    
answered by 09.01.2018 в 12:41