I want to prevent user to save the workbook with the same name as it is opened with, and to offer SaveAs option.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If ThisWorkbook.Name = "abc" Then
Cancel = True
SaveAsUI = True
End If
Also tried
If ThisWorkbook.Name = "abc" Then SaveAsUI = True
This code doesn’t work. SaveAs dialog doesn’t appear.
Next try
If ThisWorkbook.Name = "abc" Then ThisWorkbook.ReadOnly = True
'Error - can't assign to read only property.
If you want to test for a particular filename only – say
abc.xlsmthen the code below will stop theSave(but passSaveAs) then set theReadOnlyattribute to False soSavecan’t be used again on this file in this session