This code allows you to simply click a button, open a dialog to define the save location and hit OK. Then it pulls the text from a defined cell and saves the file.
This all works fine unless there is a File will the same name in the same location. Then it gives runtime error "1004", and cannot access "file name".
I would like it to either overwrite the file or Add a sequential number to the end of the file name and then save. Is this possible?
This all works fine unless there is a File will the same name in the same location. Then it gives runtime error "1004", and cannot access "file name".
I would like it to either overwrite the file or Add a sequential number to the end of the file name and then save. Is this possible?
VBA Code:
Sub SaveFile()
Application.ScreenUpdating = False
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
If .SelectedItems.Count > 0 Then
sPath = .SelectedItems(1)
ActiveWorkbook.SaveAs Filename:=sPath & Application.PathSeparator & Sheets("Sheet1").Range("L26") & ".xlsm", FileFormat:=52
End If
End With
Application.ScreenUpdating = True
End Sub