【发布时间】:2019-02-20 21:48:39
【问题描述】:
我的代码包含用于保存文档 (Excel 365) 的业务逻辑,以确保正确的命名约定、文件位置等作为 Sub Workbook_BeforeSave
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Cancel = True ''Cancels the Save from the button push or Ctrl+S
Application.EnableEvents = False
'' code code code
Application.EnableEvents = True
End Sub
问题在于,如果文件以只读方式打开(大多数情况下),Excel 将提示“文件为只读”(图 a)并转到“文件”功能区中的“另存为”屏幕(图b)。在按下 SAVE 按钮之前,Workbook_BeforeSave sub 不会启动。即使在子程序运行后,它也不会离开此屏幕。
有什么办法:
- 在只读提示符前面...或
- 编写一些代码以离开“另存为”屏幕?
MS Read-Only promt(图一) Save As Screen(图二)
提前非常感谢!
【问题讨论】:
标签: excel vba before-save