VB.NET 禁用EXCEL宏
在调用EXCEL表格时怎么样只调用文件本身,而不触发EXCEL的事件呢?如EXCEL的OPEN和Workbook_BeforeSave事件:
Private Sub Workbook_Open()
Sheet1.Cells(2, 1) = "打开工作表事件"
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheet1.Cells(3, 1) = "保存工作表前事件"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim saveDialog As New SaveFileDialog
saveDialog.FileName = "C:\database" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls"
saveDialog.Filter = "xls | *.xls"
Dim myexcel As New Excel.Application
myexcel.Visible = True
'myexcel.Workbooks.Add()
Dim xlwkbook As Excel.Workbook
Dim xlwksheet1 As Excel.Worksheet
'Dim col As Integer
'Dim row As Integer
xlwkbook = myexcel.Workbooks.Open("C:\database\test.xls")
xlwksheet1 = xlwkbook.Worksheets(1)
xlwksheet1.Cells(4, 2).Value = "SS 2012"
'xlwkbook.SaveAs(saveDialog.FileName)
xlwkbook.RunAutoMacros(xlAutoClose)
xlwkbook.Save()
xlwkbook.Close()
myexcel.Quit()
myexcel = Nothing
xlwkbook = Nothing
xlwksheet1 = Nothing
End Sub
[解决办法]
RunAutoMacros(xlAutoClose) 只是调用一个特定命名的宏 Auto_Close() 而已,和事件有什么关系?