Locking code from viewing problem

Turnkey

New Member
Joined
Aug 29, 2003
Messages
22
I have an workbook which can only be closed via a button on my menu screen. The button runs a 'quit' macro which saves and quits. I've turned off the 'close' on my userforms and have a put 'cancel=true' into my workbook before close event. It was suggested to me that in order to avoid the workbook before close event i needed to turn DoEvents to false in my 'quit' macro. I did that. All worked fine until I tried to protect the code from being viewed then all hell broke loose! I went into Project Properties applied the lock for viewing and password. Went to save and then Runtime 1004 document not saved appeared. It took me a while to go back into project properties and just remove the check mark in the lock for viewing. I left the passwords in the boxes because if I remove them the same 1004 keeps coming up. What am I doing wrong? My code is as follows:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ScreenUpdating = False
Cancel = True
End Sub

Sub quitter()
Application.ScreenUpdating = False
resetwindow - just reset's window and menubars
UserForm1.Hide
ActiveWorkbook.Save
Application.EnableEvents = False
Application.Quit
End Sub

Private Sub CommandButton5_Click() - button code
quitter
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
try

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean) 
Application.ScreenUpdating = False 
If userform1.visible = true then
else
Cancel = True 
end if
End Sub 

Sub quitter() 
Application.ScreenUpdating = False 
resetwindow - just reset's window and menubars 
ActiveWorkbook.Save 
Application.DisplayAlerts = False 
Application.Quit 
End Sub 

Private Sub CommandButton5_Click() - button code 
quitter 
End Sub
 
Upvote 0
Thanks for the pointers mate but I told you wrong. I don't know why userform1.hide is in my 'quitter' code. I just copied it straight here. That form is closed long ago. The last screen the user sees is a menu screen which is a worksheet with button on it. Can I do the same as you suggested in another way?
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,684
Members
449,048
Latest member
81jamesacct

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