I have created a workbook that is used by a team as a template. It should be opened and then saved with a new name to a new location. To protect the “master” file the routine provides a filename constructed from key cells in the workbook when saving for the first time. The file saving works fine but when I next try the ‘Save’ or ‘Save As’ functions from the Menu or Task bars, they are disabled.
I tried adding in the ‘EndOfSub:’ block the line “Cancel=False”, thinking this would turn on the ‘Save’ dialog, but Excel hangs, then shuts down.
Can anyone please offer any insight to my problem?
Thanks in advance.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim NewFileName As String
Dim Instr1 As String
Dim Response As Integer
' Error Trap
On Error GoTo Etrap
Instr1 = "Save Manufacturing Study file as:"
NewFileName = Worksheets("Data").Range("NewFileName")
Application.EnableEvents = False
Cancel = True
' Check if new or existing file
MyName
If MyName <> "Manufacturing Study_v3.0.xls" Then
GoTo EndOfSub
End If
' Check parts of FileName
If Worksheets("Summary").Range("PROC") = "" Or Worksheets("Summary").Range("LOCN") = "" Then
MsgBox "Please type in Process description and Location, for automatic file name", vbInformation, "Manufacturing Study Save"
GoTo EndOfSub
End If
' Ask User to Save
Response = MsgBox(NewFileName, vbYesNoCancel, Instr1)
Select Case Response
Case vbYes ' Save active workbook as new workbook
ThisWorkbook.SaveAs Filename:=NewFileName, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _
CreateBackup:=False, AddToMru:=True
MsgBox "New Workbook File Saved", vbInformation, "Manufacturing Study Save"
GoTo EndOfSub
Case vbNo
MsgBox "Be sure to 'SAVE AS' in correct folder." & Chr(13) & "Workbook changes not saved!", vbInformation, "Manufacturing Study Save"
GoTo EndOfSub
Case vbCancel
GoTo EndOfSub
End Select
Etrap:
Beep
MsgBox "Workbook changes not saved!", vbExclamation, "Manufacturing Study Save"
EndOfSub:
Application.EnableEvents = True
' Cancel = False
Exit Sub
End Sub
Bookmarks