禁用 Excel 保存选项但允许宏保存 [英] Disable Excel save option but allow macro save
本文介绍了禁用 Excel 保存选项但允许宏保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个 Excel 文件,我想禁用保存"和另存为..."选项.
I'm creating an excel file and I want to disable the 'save' and 'save as...' option.
我在网上找到了很多解决方案,比如 VBA 中的这个:
I found a lot of solutions on the internet, like this one in VBA:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox "You can't save this workbook!"
Cancel = True
End Sub
它阻止用户保存更改,但我无法保存更改,这就是问题所在,因为我需要在 VBA 代码中进行更多更改.
It prevents user from saving changes, but I can't save my changes and that's the problem because I need to do more changes in the VBA code.
有没有办法保存我的宏更改?比如管理员模式等等...?
Is there a way to save my macro changes ? Like an administrator mode etc... ?
感谢您以后的回答.
推荐答案
使用全局变量覆盖保存禁用:
Dim override as Boolean
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
if Not(override) then
MsgBox "You can't save this workbook!"
Cancel = True
end if
End Sub
Sub SaveMyChanges()
override = true
ActiveWorkbook.Save
override = false
End Sub
这篇关于禁用 Excel 保存选项但允许宏保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文