Thank you in advance for your help!
I have the code for saving my file working the way I'd like it to as long as the path already exists. When I share with my team though, they may have named their folder something different. What I'd like to do is add in error handling where if the path needed does not exist it goes to the users 'my documents' folder. I am still learning VBA but whenever I try to add it in I just end up with more errors. Thoughts?
I have the code for saving my file working the way I'd like it to as long as the path already exists. When I share with my team though, they may have named their folder something different. What I'd like to do is add in error handling where if the path needed does not exist it goes to the users 'my documents' folder. I am still learning VBA but whenever I try to add it in I just end up with more errors. Thoughts?
VBA Code:
Sub saveaswithlocationwithusernamewitherrorhandling()
Dim file_name As Variant
Dim fName As String
ChDrive "C"
ChDir "C:\Users\" & Environ("username") & "\Documents\Job Folders - 2020\" & Range("C13")
fName = "Offer Checklist - " & Range("C26").Value & " " & Range("C27").Value & " - " & Range("C13").Value
' Get the file name.
file_name = Application.GetSaveAsFilename(fName, _
Filefilter:="Excel Macro-Enabled Workbook,*.xlsm,All Files,*.*", _
Title:="Save As File Name")
' See if the user canceled.
If file_name = False Then Exit Sub
' Save the file with the new name.
If LCase$(Right$(file_name, 5)) <> ".xlsm" Then
file_name = file_name & ".xlsm"
End If
ActiveWorkbook.SaveAs Filename:=file_name, FileFormat:=52
End Sub