Results 1 to 3 of 3

Locking code from viewing problem

This is a discussion on Locking code from viewing problem within the Excel Questions forums, part of the Question Forums category; I have an workbook which can only be closed via a button on my menu screen. The button runs a ...

  1. #1
    New Member Turnkey's Avatar
    Join Date
    Aug 2003
    Posts
    22

    Default Locking code from viewing problem

    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

  2. #2
    DRJ
    DRJ is offline
    MrExcel MVP DRJ's Avatar
    Join Date
    Feb 2002
    Location
    California
    Posts
    3,856

    Default

    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

  3. #3
    New Member Turnkey's Avatar
    Join Date
    Aug 2003
    Posts
    22

    Default

    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?

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com