Note: The other languages of the website are Google-translated. Back to English
登入  \/ 
x
or
x
註冊  \/ 
x

or

如何在Excel中禁用或不允許“另存為”選項?

通常,當我們單擊“保存”或“另存為”功能時,在工作簿中修改的數據將立即保存。 但是,有時,其他用戶在讀取Excel文件時不允許他們對其進行修改和保存。 本文提供了VBA方法來禁用Excel中的“另存為”和“另存為”選項。

使用VBA代碼禁用“另存為”選項


使用VBA代碼禁用“另存為”選項

您可以運行下面的VBA代碼以禁用Excel中的“另存為”和“另存為”選項。

1.在工作簿中,您需要禁用“保存和另存為”功能,請按 其他 + F11 同時打開 Microsoft Visual Basic for Applications 窗口。

2。 在裡面 Microsoft Visual Basic for Applications 窗口,雙擊 的ThisWorkbook 在左欄中,將下面的VBA 1複製並粘貼到“代碼”窗口中,然後單擊 慳了 按鈕。 看截圖:

VBA 1:在Excel中禁用“另存為”選項

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    ThisWorkbook.Saved = True
End Sub

3.在開幕 另存為 窗口,選擇一個文件夾來保存工作簿,根據需要命名工作簿,然後選擇 Excel啟用宏的工作簿 來自 保存類型 下拉列表,最後單擊 慳了 按鈕。

4.現在,將下面的VBA 2複製並粘貼到 的ThisWorkbook 代碼窗口。 查看截圖。

VBA 2:在Excel中禁用“另存為”選項

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim xName As String
xName = "CancelBeforeSave"

If Not Evaluate("=ISREF('" & xName & "'!A1)") Then
    Sheets.Add(after:=Worksheets(Worksheets.count)).Name = xName & ""
    Sheets(xName & "").Move after:=Worksheets(Worksheets.count)
    Sheets(xName & "").Visible = False
    Exit Sub
End If
    Cancel = True
End Sub

5。 點擊 慳了 按鈕以保存代碼,然後關閉工作簿。

該工作簿已通過以下方式另存為Excel Macro-Enabled Workbook: 慳了另存為 功能已禁用。

備註:每次您修改和保存工作簿時,更改似乎都保存在當前工作表中。 但是在關閉並重新打開工作簿後,您會發現更改無法保存。


最佳辦公效率工具

Kutools for Excel解決了您的大多數問題,並使您的生產率提高了80%

  • 重用: 快速插入 複雜的公式,圖表 以及您以前使用過的任何東西; 加密單元 帶密碼 創建郵件列表 並發送電子郵件...
  • 超級公式欄 (輕鬆編輯多行文本和公式); 閱讀版式 (輕鬆讀取和編輯大量單元格); 粘貼到過濾範圍...
  • 合併單元格/行/列 不會丟失數據; 拆分單元格內容; 合併重複的行/列...防止細胞重複; 比較範圍...
  • 選擇重複或唯一 行; 選擇空白行 (所有單元格都是空的); 超級查找和模糊查找 在許多工作簿中; 隨機選擇...
  • 確切的副本 多個單元格,無需更改公式參考; 自動創建參考 到多張紙; 插入項目符號,複選框等...
  • 提取文字,添加文本,按位置刪除, 刪除空間; 創建和打印分頁小計; 在單元格內容和註釋之間轉換...
  • 超級濾鏡 (將過濾方案保存並應用於其他工作表); 高級排序 按月/週/日,頻率及更多; 特殊過濾器 用粗體,斜體...
  • 結合工作簿和工作表; 根據關鍵列合併表; 將數據分割成多個工作表; 批量轉換xls,xlsx和PDF...
  • 超過300種強大功能。 支持Office / Excel 2007-2019和365。支持所有語言。 在您的企業或組織中輕鬆部署。 完整功能30天免費試用。 60天退款保證。
kte選項卡201905

Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 每天將您的工作效率提高50%,並減少數百次鼠標單擊!
officetab底部
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Joe · 5 months ago
    Please, I do not want someone to copy or save my excel file, how can I remove save or save as?

  • To post as a guest, your comment is unpublished.
    Madhusudhan · 7 months ago
    Hello I am a fan of this website...I used to try the code. It works flawlessly. But it disables "Save option" too. I am not able to save the Excel sheet. What I need is to disable only the feature "Save As" I read the other user's comments too. ThisWorkbookSaved = True is not working for me as well. Could you please help? Thanks a lot for all your contributions.
  • To post as a guest, your comment is unpublished.
    Naomi · 1 years ago
    I keep getting debug error
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Good day,
      Which Excel version do you use?
  • To post as a guest, your comment is unpublished.
    Rogue · 3 years ago
    Just to help whoever else reads this article looking for help with suppressing the save button I thought I'd place the answer down here as "Crystal" doesn't seem to be answering the question....


    If you place the workbook in "Design Mode" and then hit SAVE it should work.
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Dear Rogue,
      I miss the point of the problem. Thank you so much for your help and sharing.

      Best Regards
  • To post as a guest, your comment is unpublished.
    What they said · 3 years ago
    As TEE and LES posted, how do we save the file with the macro in?
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Hi,
      Thank you for your question. The article is updated to support saving the code into workbook now.
  • To post as a guest, your comment is unpublished.
    Les Battersthee · 3 years ago
    As TEE posted, how do we save the file with the macro in? It is not there when I reopen. I am also now getting a bug on the ThisWorkbookSaved = True bit.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear Les,
      Thank you for your question. The article is updated to support saving the code into workbook now.
  • To post as a guest, your comment is unpublished.
    tee · 4 years ago
    this doesn't work. I can't save the code it's gone once I reopen the file. How do I save the code?
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Dear tee,
      Thank you for your question. The article is updated to support saving the code into workbook now.
      • To post as a guest, your comment is unpublished.
        jen · 2 years ago
        dear
        the article is not updated. it doesnt work
        • To post as a guest, your comment is unpublished.
          crystal · 2 years ago
          Hi jen,
          The article has been updated again with the problem solving. Please have a try. Thank you for your comment.
          • To post as a guest, your comment is unpublished.
            I.C. Problems · 1 years ago
            The update to the code adds a sheet, but never actually checks whether there is a TRUE/FALSE value in that sheet. The update fixes nothing, it just creates a useless sheet within the workbook.

            I think you forgot to do a check whether there is a TRUE/FALSE value on that sheet.