Reputation: 3
I want to save as an excel file as .csv
from Sheet2
(Sheet name changes) so I want excel to pop up a message if I try to save as the file from Sheet1
. I've a code to pop up the message but I'm not sure how to apply if condition for this scenario. Thank you for your help!!
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean)
If SaveAsUI Then
MsgBox "Make sure you are on correct sheet"
End If
End Sub
Upvotes: 0
Views: 167
Reputation: 6654
This Should Work for you:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
If ActiveSheet.Name = "Sheet1" Then
MsgBox "Make sure you are on correct sheet"
SaveAsUI = False
End If
End If
End Sub
If you are on Sheet1, the Msgbox will pop and sheet won't be saved.
Upvotes: 2