Programmatically Insert Code in a Presentation
MS Office 2004 defines the modules that can contain
code as VBComponents. The VBComponent types include Standard Modules, Slides,
Forms, etc. The following code accepts a Presentation and the code as input
parameters. It will create Standard Module type VBComponent if required and add
the code in it.
Microsoft Visual Basic for Applications
Extensibility needs to be included in the set of references. To
add a reference to it
- Select Tools | References....
- Select Microsoft Visual Basic for Applications Extensibility
from the available references.
- Click OK.
Sub InsertCode(ByVal Pres
As Presentation, ByVal Code
As String)
Dim CM As CodeModule
Dim I As Long
For I = 1 To Pres.VBProject.VBComponents.Count
With Pres.VBProject.VBComponents(I)
If .Type = vbext_ct_StdModule
Then
Set CM = .CodeModule
End If
End With
Next
If CM Is Nothing Then
Set CM = Pres.VBProject.VBComponents.Add( _
vbext_ct_StdModule).CodeModule
End If
CM.AddFromString Code
End Sub
|
|
|