Before Save Event

GeorgeB

Board Regular
Joined
Feb 16, 2002
Messages
239
Good day all
Trying to remind the user to save a template as something else. This must be basic VBA but I can't put my finger on the problem.
I get run time error 91 object variable not set with this.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim MyWkbk As Workbook

If MyWkbk.Name = Book3.xls Then

MsgBox prompt:="Don't step on the template"

End If
End Sub
 
Thanks to TsTom, Dreamboat and Dave Hawley for your kind responses. Here is the final code. It reminds the user not to step on the template.
"I get by with a little help from my friends"

Private Sub Workbook_Open()
Dim wBook As Workbook
Dim Response As Integer
'Test for template name. Exit if it has been changed.
Set wBook = ActiveWorkbook
If wBook.Name <> "Nevada Estimating 5.0.xls" Then
Exit Sub
End If
'Display splash screen reminder to enter new job into the log.
UserForm1.Show
'Remind user to save it as a new job.
Response = MsgBox(prompt:="PLEASE SAVE THE FILE TO A NEW NAME.", _
Buttons:=vbOKCancel + vbExclamation, Title:="REMINDER")
'Bring up the Save As screen.
If Response = vbOK Then
Application.Dialogs(xlDialogSaveAs).Show ("*.xls")
End If
End Sub

Have a great day
George
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,213,522
Messages
6,114,112
Members
448,549
Latest member
brianhfield

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top