Hello.
I'm looking for a way to backup a folder. This contains subfolders at various levels and files. I have created an example folder for you. I also copy the code that I use and it does not copy everything, only the folders with a single level.
I want it to copy all the files except the shortcuts and, importantly, if a file is open, to copy it too. With the latter I had problems with this code that I copy below, one of the times I copied it, someone on another computer different from mine (it is shared on the network) had it open and it gave me an error.
Thank you so much.
I'm looking for a way to backup a folder. This contains subfolders at various levels and files. I have created an example folder for you. I also copy the code that I use and it does not copy everything, only the folders with a single level.
VBA Code:
Sub CopiarDocumentacion()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error Resume Next
Dim fso As Object
Dim CarpetaOrigen As String
Dim CarpetaDestino As String
Set fso = CreateObject("Scripting.FileSystemObject")
CarpetaOrigen = "C:\Users\Diego\Escritorio\Documentación"
CarpetaDestino = "C:\Users\Diego\Escritorio\Organizar\Nuevo. Guardar\00 Copia de seguridad\Documentación"
fso.CopyFolder CarpetaOrigen, CarpetaDestino
MsgBox ("La carpeta se copió con éxito."), vbInformation, "Copia de seguridad"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
I want it to copy all the files except the shortcuts and, importantly, if a file is open, to copy it too. With the latter I had problems with this code that I copy below, one of the times I copied it, someone on another computer different from mine (it is shared on the network) had it open and it gave me an error.
Code:
Sub CopiarVacaciones()
Dim RutaOrigen As String
Dim RutaDestino As String
' Rutas de origen y destino
RutaOrigen = Range("I1").Value
RutaDestino = "C:\Users\20ZU0050\Desktop\00 Copia de seguridad\Vacaciones 2022.xlsx"
' Copiar el archivo
FileCopy RutaOrigen, RutaDestino
MsgBox "Hemos copiado la ruta del archivo " & RutaOrigen & " en la nueva ubicación (" & RutaDestino & ").", vbInformation, "Copia de seguridad"
End Sub
Thank you so much.