class=y2iqfc>Greetings dear friends, please can you help me with this query.
style='font-size:21.0pt;font-family:inherit;color:#202124;mso-ansi-language:
EN'>I found a very interesting macro by which files in a folder are opened using a macro from a file in which Sheet 1 contains the name of the files and the password
style='font-size:21.0pt;font-family:inherit;color:#202124;mso-ansi-language:
EN'>What I need is that with an identical sheet in which the lists of the open files are found and with the keys for each one, they are saved and closed in the same folder that they were originally opened.
style='font-size:21.0pt;font-family:inherit;color:#202124;mso-ansi-language:
EN'>I attached the macro
Thank you
Sub AbrirArchivosConContraseña()
Dim ws As Worksheet
Dim wb As Workbook
Dim filePath As String
Dim password As String
Dim lastRow As Long
Dim i As Long
Dim currentPath As String
' Establece la hoja donde está la tabla
Set ws = ThisWorkbook.Sheets(1) ' Cambia el índice o nombre de la hoja según sea necesario
' Encuentra la última fila con datos en la columna A
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' Obtén la ruta del directorio actual
currentPath = ThisWorkbook.Path
' Recorre cada fila de la tabla para abrir los archivos
For i = 2 To lastRow
' Obtén el nombre del archivo y la contraseña de la tabla
filePath = currentPath & "\" & ws.Cells(i, 1).Value
password = ws.Cells(i, 2).Value
' Intenta abrir el archivo con la contraseña
On Error Resume Next
Set wb = Workbooks.Open(Filename:=filePath, password:=password)
If Err.Number <> 0 Then
MsgBox "No se pudo abrir el archivo: " & filePath & " con la contraseña proporcionada.", vbExclamation
Err.Clear
End If
On Error GoTo 0
Next i
End Sub
style='font-size:21.0pt;font-family:inherit;color:#202124;mso-ansi-language:
EN'>I found a very interesting macro by which files in a folder are opened using a macro from a file in which Sheet 1 contains the name of the files and the password
style='font-size:21.0pt;font-family:inherit;color:#202124;mso-ansi-language:
EN'>What I need is that with an identical sheet in which the lists of the open files are found and with the keys for each one, they are saved and closed in the same folder that they were originally opened.
style='font-size:21.0pt;font-family:inherit;color:#202124;mso-ansi-language:
EN'>I attached the macro
Thank you
Sub AbrirArchivosConContraseña()
Dim ws As Worksheet
Dim wb As Workbook
Dim filePath As String
Dim password As String
Dim lastRow As Long
Dim i As Long
Dim currentPath As String
' Establece la hoja donde está la tabla
Set ws = ThisWorkbook.Sheets(1) ' Cambia el índice o nombre de la hoja según sea necesario
' Encuentra la última fila con datos en la columna A
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' Obtén la ruta del directorio actual
currentPath = ThisWorkbook.Path
' Recorre cada fila de la tabla para abrir los archivos
For i = 2 To lastRow
' Obtén el nombre del archivo y la contraseña de la tabla
filePath = currentPath & "\" & ws.Cells(i, 1).Value
password = ws.Cells(i, 2).Value
' Intenta abrir el archivo con la contraseña
On Error Resume Next
Set wb = Workbooks.Open(Filename:=filePath, password:=password)
If Err.Number <> 0 Then
MsgBox "No se pudo abrir el archivo: " & filePath & " con la contraseña proporcionada.", vbExclamation
Err.Clear
End If
On Error GoTo 0
Next i
End Sub