禁用保存按钮在从vb.net加载的Excel文档中

时间:2016-12-21 15:54:28

标签: excel vb.net

我正在使用如下所示的代码加载Excel文档:

Dim exApp As New Excel.Application
Dim exWB As Excel.Workbook = exApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet)
Dim exSheet As Excel.Worksheet
exSheet = exWB.ActiveSheet

有没有办法为生成的文档禁用“保存”和“另存为”按钮?到目前为止,我发现的唯一解决方案是写入宏,但这不是我追求的。我需要能够从vb.net应用程序中禁用它们。

由于

1 个答案:

答案 0 :(得分:3)

你能试试这段代码吗?

AddHandler exWB.BeforeSave, AddressOf Workbook_BeforeSave

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, ByRef Cancel As Boolean)
    MsgBox("You are not enable to save.")
    Cancel = True
End Sub