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应用程序 窗口。

2。 在里面 Microsoft Visual Basic应用程序 窗口,双击 的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 · 3 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.