presentation has a macro?

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
 
C

Chirag

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
 
G

Geoff Cox

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
 
G

Geoff Cox

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
 
S

Shyam Pillai

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top