簡體   English   中英

刪除工作表MS Excel之前顯示消息框

[英]Display Message Box Before Deleting Sheet MS Excel

我正在尋找一種防止用戶刪除用作每日報告模板的電子表格的方法。 用戶應該將電子表格的名稱更改為今天的日期(即01-14),然后運行一個宏,該宏創建今天的工作表副本並將其重命名為“ New Day”。 我需要確保用戶不能刪除“ New Day”表,因為它包含公式。 我很討厭使用MS Excel 2007。

感謝您提供任何幫助!

嘗試在原始紙上Protect Sheet紙。

轉到ReviewProtect Sheet 確保選擇了“保護工作表和鎖定單元格的內容”,並且如果您沒有輸入密碼,則該表是受保護的,但是有人可能會付出一些努力來取消保護。 但是,如果您只擔心他們不小心刪除了工作表,那么這肯定會有所幫助。

今天上午,這在Excel 2010上對我來說效果很好,請在2007年對其進行測試,然后告知我。

將以下內容粘貼到特定的工作表模塊中。

 Private Sub Worksheet_Activate()
   ThisWorkbook.Protect "yourpassword"
 End Sub

 Private Sub Worksheet_Deactivate()
   ThisWorkbook.Unprotect "yourpassword"
 End Sub

這在Excel 2010中非常有效,可以編輯和刪除單元格/行/列。

然后,當您要復制時,您將需要Select另一張紙進行查看,因為一旦選擇了特定的紙,它將應用密碼,從而將所選內容刪除到“移動/復制/刪除”中。 這也將適用於復印頁。

Sub SomeSub()

    Dim MySheet As Worksheet

    Set MySheet = ThisWorkbook.Sheets("Sheet1")

    'Due to the the Protection of the Sheet while it is active
    'you then need to select another sheet
    ThisWorkbook.Sheets("Sheet2").Select

    'With the Sheet not being active you don't need to unprotect it
    'because the password is not applied.
    MySheet.Copy After:=Sheets(2)

    'Note that the Copied Sheets will be protected with the
    'same password used for the original sheet, and this Only applies with access through VBA.

End Sub

讓我知道是否還有其他需要解釋的內容,或者是否行不通。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM