I'm trying to create a macro to have the user save a backup of the workbook to a specific place. I tried my code below but got an error 13 message. I don't need it to be saved as a macro-enabled workbook, but I thought that would be easier.
Sub openSaveDialog()
'
' gives error 13 message when clicking save
'
Dim saveSuccess As Boolean
Dim fNameRec As String
Dim dateNow As String
Dim saveToDir As String
saveToDir = "Z:\location of save\Old Archive spreadsheets\"
dateNow = Format(Now(), "mmddyyyy")
fNameRec = saveToDir & "BinderArchiveBackup_" & dateNow
Sheets(3).Range("E25") = fNameRec
'check if backed up today
If (Sheets(3).Range("E22") = Date) Then
MsgBox "backup already saved today no need to save again"
Exit Sub
End If
'open save as window
saveSuccess = Application.GetSaveAsFilename(InitialFileName:=fNameRec, FileFilter:= _
"Excel Files (*.xlsx)," & "*.xlsx, Macro Enabled" & _
"Workbook (*.xlsm), *xlsm")
'if backup saved, update date of last backup
If saveSuccess Then
Sheets(3).Range "E22" = Date
MsgBox "save successful"
End If
'if backup not saved, inform user
If Not saveSuccess Then
MsgBox "save canceled, please save backup before adding new items to the archive today"
End If
End Sub
Things I tried tweaking
- File filter to just macro enabled
- File filter to just excel workbook
- Blank file filter saving as type all files
- Blank file filter with .xlsx at the end of the name
- initial filename without directory but with ChDir so it opens in the right save location anyway
Any help would be great.
Save as window that opens