Are you finding the problem when you're testing?
If you are, then I bet that you're resetting that myLocked variable
inadvertently.
It could be that you're hitting the Reset button in the VBE.
(Or you could have an "End" (not "End if", "End Select", "End Sub") line in your
code.)
Either of these will reset all these public variables (to 0's for numbers, empty
strings for text, nulls for variants, and false for booleans).
Patrick C. Simonds said:
Thanks for your patients, let me try to explain.
When UserForm1 displays the user is presented with 2 optionsbuttons. Option
1 open the file for viewing only (Optionbutton 1 is set to true by default),
Option 2 to edit the file.
If they select Option 1, the workbook is opened and protected to the point
that the user can not edit the workbook in any way. If the chose Option 2
(to edit the workbook) they must provide a password to continue.
All of that works well. My issue is, that if the user selects Option 1 (to
view only) I do not want them to be able to save/save as the workbook. So
once they click on Commandbutton1 to accept Option1 the Userform is closed
and the user then browses the workbook viewing the information within. I
then created the routine below to prevent the save As function from working
but it apparently does not see that myLocked = True.
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
"
If myLocked = True Then
If SaveAsUI = True Then Cancel = True
End If
End Sub