presentation has a macro?

  • Thread starter Thread starter Geoff Cox
  • Start date Start date
G

Geoff Cox

Hello,

Anyone know how to fiind if a presentation has a macro?

I need a vba approach as I would like to check lots of files.

I came across the following,

If oPresentation.VBProject.VBComponents.Count > 0 Then
MsgBox "The presentation contains forms, modules, or classes."
End If

The above code will find a module which is empty so that does not
really help.

Cheers,

Geoff
 
You need to iterate over the code to find the procedures. The following code
does exactly that:

---
Function DoesMacroExist(ByVal Pres As Presentation) As Boolean
Dim MacroExists As Boolean
Dim I As Long
Dim StartLine As Long

With Pres.VBProject
MacroExists = (.VBComponents.Count > 0)
If MacroExists Then
MacroExists = False

For I = 1 To .VBComponents.Count
With .VBComponents(I).CodeModule
StartLine = .CountOfDeclarationLines + 1
Do While StartLine < .CountOfLines
MacroExists = (.ProcOfLine( _
StartLine, vbext_pk_Proc) <> "")
If MacroExists Then
Exit Do
End If

StartLine = StartLine + 1
Loop

If MacroExists Then
Exit For
End If
End With
Next
End If
End With

DoesMacroExist = MacroExists
End Function
---

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 
You need to iterate over the code to find the procedures. The following code
does exactly that:

Chirag,

Thanks for the code below - could you help me with next step?

I need to call the function for a whole series of files (file name
strMyFile) - following is my first shot and is obviously not correct
-how do I get the result re if there is a macro?

Sub macro_here(strMyFile As String)

Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)

Call DoesMacroExist(oPresentation)


oPresentation.Close
Set oPresentation = Nothing

End Sub

Thanks

Geoff
 
You need to iterate over the code to find the procedures. The following code
does exactly that:

Chirag,

I seem to have got the idea re calling your function for a series of
..ppt files? This seem OK?

Cheers,

Geoff

Sub macro_here(strMyFile As String)

Dim oPresentation As Presentation
Set oPresentation = Presentations.Open(strMyFile)

Call DoesMacroExist(oPresentation)

If DoesMacroExist(oPresentation) Then
MsgBox "macro present in " & strMyFile
End If

oPresentation.Close
Set oPresentation = Nothing

End Sub
 
Hi Geoff,
Note that Chirag's code requires a reference to the Microsoft Visual Basic
for Aplications Extensibility library in your project. You will also need
to turn on programmatic access to the Visual Basic project from the Macro
Security settings.


--
Regards,
Shyam Pillai

Animation Carbon
http://www.animationcarbon.com
 
Hello,

Anyone know how to fiind if a presentation has a macro?

I need a vba approach as I would like to check lots of files.

I came across the following,

If oPresentation.VBProject.VBComponents.Count > 0 Then
MsgBox "The presentation contains forms, modules, or classes."
End If

The above code will find a module which is empty so that does not
really help.

Help do what, though? ;-)

If you're trying to pinpoint presentations that might trigger a macro warning
elsewhere, then you'll want to find those that have modules, empty or not, I'd
think (though admittedly thinking isn't always the best substitute for
empirical evidence).
 
Back
Top