2

does anyone know a programmatic way to determine whether an excel file has a macro with it? i have hundreds of excel files and i need to know which files have macros in them?

2 Answers 2

2

I have tried it with 2 workbooks (1 having macros & another without the macros).

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

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

2

You can iterate through the collection Workbook.VBProject.VBComponents

If you find anything in there, you have macros

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.