检查Excel工作簿是否使用C#macros
我需要通过数百个Excel文件来find那些有macros的,使用C#客户端。
我已经尝试在这里接受的答案使用代码:
使用Interop.Excel检查Excel文件是否包含VBAmacros
但是,此代码首先打开文件。 即使添加了_appExcel.DisplayAlerts = false
许多文件也会popupWindows和VBA错误消息
它也很慢。 有没有更好的方法去解决这个问题,理想情况下不要先打开Excel文件?
我在这里find了MSDN for Excel interop的文档: HasVBProject,但是没有任何可以使用的例子。
如果工作簿事件的问题比通过AutomationSecurity
属性禁用所有使用Interop.Excel
命名空间的macros,
MyExcel.Application.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityForceDisable;
尝试这个
f = Dir("*.xls*") While f <> "" On Error Resume Next Set wb = Workbooks.Open(f) If wb.HasVBProject Then Debug.Print wb.Name & " has macro" Else Debug.Print wb.Name & "does not have macro" End If wb.Close f = Dir Wend