Have code to block Save but how to keep code in workbook without saving the file?

  • My company has files that are already in use. I don't know too many details about how they work, but somehow saving the file will screw it up and my boss has to go back and reset something or other to correct it. Obviously it's connected to some other software somewhere. The code below will block Save and Save-As. BUT how do I get the file to hold onto the code without actually saving the file after the code is added (since the file shouldn't be saved)?


  • Re: Have code to block Save but how to keep code in workbook without saving the file?


    Your boss is going to have to go in one more time and fix whatever he fixes after you save the changes...


    You also overcomplicate things...

    Code
    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) 
    
    
            Cancel = True 
             
            MsgBox "You cannot save this workbook." 
         
    End Sub


    Have you considered what happens if the user does not enable macros when the workbook is opened...?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!