Forum Discussion
LesKing
May 05, 2023Brass Contributor
Macro to create a backup of current workbook
Hi, I need a macro to create a backup of my current workbook into a different folder than the one the workbook is saved in. I've found code on the internet and youtube but nothing seems to work (I ...
HansVogelaar
May 05, 2023MVP
Try this:
Sub CreateBackup()
Const strFolder As String = "C:\Backup\"
Dim strFile As String
Dim lngPos As Long
strFile = ActiveWorkbook.Name
lngPos = InStrRev(strFile, ".")
strFile = Left(strFile, lngPos - 1) & Format(Now, "_yyyymmdd_hhmmss") & Mid(strFile, lngPos)
ActiveWorkbook.SaveCopyAs strFolder & strFile
End Sub- LesKingMay 05, 2023Brass ContributorThank you, Hans - you truly are a star!!!
This worked perfectly.
I'm a VBA newbie and I have managed quite a lot, but I still have mountains to learn, and it's great this Excel Community exists, and there are fantastic people like you to be an expert guide.
Thanks again, Les King