有没有人知道一种编程方式来确定excel文件是否有宏?我有数百个excel文件,我需要知道哪些文件中有宏?
答案 0 :(得分:2)
您可以遍历集合Workbook.VBProject.VBComponents
如果你在那里找到任何东西,你就有了宏
Algorightm
Loop through all XLS workbooks
Open Workbook
If Workbook.VBProject.VBComponents.Count > 0 Then
HasCodBehind = True
'// Do what you need to here
End If
Close Workbook
End Loop
答案 1 :(得分:2)
我已经尝试了2个工作簿(1个有宏,另一个没有宏)。
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Workbooks.Open("c:\temp\myfileWithMacros.xls")
Msgbox ActiveWorkBook.HasVBProject
ActiveWorkBook.Close
Workbooks.Open("c:\temp\myfileWithoutMacros.xls")
Msgbox ActiveWorkBook.HasVBProject
ActiveWorkBook.Close
希望有所帮助。