简体   繁体   中英

How to disable save and protected sheet prompt in excel using VBA

I have an excel sheet which is protected, since the sheet is protected I don't want the user to save it, and I don't want the save the sheet prompt to appear when someone closes the workbook. Till now I have been using this:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Cancel = True
    Application.DisplayAlerts = False
End Sub

Using this code, save feature is disabled but the prompt is still appearing

Similar problem:
Since the workbook is protected whenever someone tries to change the cell content it displays an alert, I want to disable that prompt message as well. Can someone help me to fix this

L42 has already answered part of your question.

I want to disable that prompt message as well.

Do this. While protecting the sheet, unckeck the option Select Locked Cells . Now that will take care of the keyboard input while the sheet is locked and protected.

在此输入图像描述

As for mouse inputs ie the prompt showing up when you double click on the cell, use this :)

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM