View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default How to determin a Excel file has Macro

I thought I would put theory to the test.
You need to add a reference (From Tools menu, References) to "Microsoft
Visual Basic for Applications Extensibility"

Sub testit()
Dim wkb As Workbook, vbc As VBComponent, i As Long, blnFound As Boolean

For Each wkb In Workbooks
blnFound = False
For Each vbc In wkb.VBProject.VBComponents
With vbc.CodeModule
For i = 1 To .CountOfLines
If .ProcOfLine(i, vbext_pk_Get) < "" Or _
.ProcOfLine(i, vbext_pk_Let) < "" Or _
.ProcOfLine(i, vbext_pk_Proc) < "" Or _
.ProcOfLine(i, vbext_pk_Set) < "" Then
blnFound = True
Exit For
End If
Next
End With
If blnFound Then Exit For
Next
MsgBox wkb.Name & ": macros " & IIf(blnFound, "", "not ") & "found"
Next
End Sub


"Rob van Gelder" wrote in message
...
This would be very difficult to get working accurate first cut.

I would inspect the code modules of each VBComponent inside the workbook.
Try doing a lookup on ProcOfLine. You could loop through each line

checking
for at least one procedure. If one exists you could assume the workbook

has
macros?



"Winston Lee" wrote in message
...
Hi All:
I have a lot of Excel files. I hope to demarcate
the Excel files that have macro. Is there any tools or how
to program ?


Thanks
Best Regards