Solved

How to recognize if a *.xls contains macros

Posted on 2014-09-09
2
107 Views
Last Modified: 2014-09-25
Hi

Do you know a tool or command which lists all *.xls containing macros (vba code) ?

thx
guenter
0
Comment
Question by:haslinger
2 Comments
 
LVL 26

Accepted Solution

by:
ProfessorJimJam earned 500 total points
ID: 40312320
open a excel worksheet, insert a module and then change the path to the path where your files are and then run it. it will show in msgbox all the files containing macros.

Sub FindMacros()
    Dim sPath As String
    Dim sFile As String
    Dim sFoundFiles As String

    'specify directory to use - must end in "\"
    sPath = "C:\"

    sFile = Dir(sPath)
    Do While sFile <> ""
        If InStr(sFile, ".xls") > 0 Then
            Workbooks.Open (sPath & sFile)
            If Workbooks(sFile).HasVBProject Then
                sFoundFiles = sFoundFiles & sFile & vbCrLf
            End If
            Workbooks(sFile).Close (False)
        End If
        sFile = Dir     ' Get next filename
    Loop
    If Len(sFoundFiles) = 0 Then
        MsgBox "No workbooks found that contain macros"
    Else
        sFoundFiles = "The following workbooks contain macros:" & _
          vbCrLf & vbCrLf & sFoundFiles
        MsgBox sFoundFiles
    End If
End Sub

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question