PDA

View Full Version : How to include forms and code modules into dozens of separate PPTs?



TrentLane
02-18-2021, 11:04 AM
I have several dozen PPTs which I want to include various forms and code modules into. I created them in a development PPT but I need to use their code/forms in all the other PPTs.

Does VBA have some kind of #include function that allows me to easily include code/forms from another PPT?

Thank you.

John Wilson
02-19-2021, 07:13 AM
If you have exported the modules / forms you can import them using the IMPORT method

ActivePresentation.VBProject.VBComponents.Import ("full path")

You would need to go to Trust Center and enable access to the vb project as this is disabled by default

TrentLane
02-19-2021, 11:18 AM
That worked *perfectly*. Thank you.

One final thing... I created a button by manually inserting a shape (that looks like a button) then setting it's "action" to execute the main Sub code section. I keep this shape out of view until I need to run code, then I move it into the primary display area, run PPT in Reading View, which allows the button to serve as a VBA execute button. Is there a way to use VBA to generate this 'button' (with Action pointing to VBA code) if it doesn't already exist?

John Wilson
02-20-2021, 08:11 AM
Not sure if this is what you mean but should help ;


Dim oshp As ShapeSet oshp = ActivePresentation.Slides(1).Shapes.AddShape _
(Type:=msoShapeRectangle, Left:=10, Top:=10, Width:=200, Height:=100)
With oshp.ActionSettings(ppMouseClick)
.Action = ppActionRunMacro
' run macro named 'chex'
.Run = "chex"
End With