VB.NET如何禁用EXCEL宏
在调用EXCEL表格时怎么样只调用文件本身,而不触发EXCEL的事件呢?如EXCEL的OPEN和Workbook_BeforeSave事件:
Visual Basic code?Private Sub Workbook_Open() Sheet1.Cells(2, 1) = "打开工作表事件"End SubPrivate Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Sheet1.Cells(3, 1) = "保存工作表前事件"End Sub
xlwkbook.RunAutoMacros(xlAutoClose) 可以关闭宏,但是还是触发了EXCEL的事件:
Visual Basic code?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
有高人指点下调用EXCEL而不触发文件本身的事件吗?谢谢了.
RunAutoMacros(xlAutoClose) 只是调用一个特定命名的宏 Auto_Close() 而已,和事件有什么关系?
EXCEL表格的代码就是不能动.能删除就好了.VB.net没有打开EXCEL就只能直接启用宏吗?有没有可以实现EXCEL设置宏安全性的那种,设置为高 ,这样打开就不用触发里面的事件了.