public static void Run()
{
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_VBA();
// ExStart:AddVBAMacros
// Instantiate Presentation
using (Presentation presentation = new Presentation())
{
// Create new VBA Project
presentation.VbaProject = new VbaProject();
// Add empty module to the VBA project
IVbaModule module = presentation.VbaProject.Modules.AddEmptyModule("Module");
// Set module source code
module.SourceCode = @"Sub Test(oShape As Shape) MsgBox ""Test"" End Sub";
// Create reference to <stdole>
VbaReferenceOleTypeLib stdoleReference =
new VbaReferenceOleTypeLib("stdole", "*\\G{00020430-0000-0000-C000-000000000046}#2.0#0#C:\\Windows\\system32\\stdole2.tlb#OLE Automation");
// Create reference to Office
VbaReferenceOleTypeLib officeReference =
new VbaReferenceOleTypeLib("Office", "*\\G{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}#2.0#0#C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE14\\MSO.DLL#Microsoft Office 14.0 Object Library");
// Add references to the VBA project
presentation.VbaProject.References.Add(stdoleReference);
presentation.VbaProject.References.Add(officeReference);
// ExStart:AddVBAMacros
// Save Presentation
presentation.Save(dataDir + "AddVBAMacros_out.pptm", SaveFormat.Pptm);
}
}
}