?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
Sub ChangeBackColor() 'Change backcolor of slides 1, 2 and 3
With ActivePresentation.Slides.Range(Array(1, 2, 3))
.FollowMasterBackground = msoFalse
.Background.Fill.ForeColor.SchemeColor = ppAccent2
End With
End Sub
Sub ChangeText(vArray As Variant)
'Add a text box to each slide and use the text from the
'array passed into this procedure
Dim s As Slide
For i = 1 To ActivePresentation.Slides.Count
With ActivePresentation.Slides(i).Shapes.AddTextbox( _
msoTextOrientationHorizontal, 186#, 54#, 336#, 36#)
.TextFrame.TextRange.Text = vArray(i - 1)
.TextFrame.TextRange.Font.Size = 60
End With
Next
End Sub
_Application oApp;
if(!oApp.CreateDispatch("Powerpoint.Application"))
{
AfxMessageBox("Could not get Powerpoint application.");
return;
}
oApp.SetVisible(TRUE);
//Get the Presentations collection and open a presentation
Presentations oPresSet(oApp.GetPresentations());
CString strFilename;
//For PowerPoint 2007, change the file name to "c:\\pres.pptm"
strFilename = "c:\\pres.ppt";
_Presentation oPres(oPresSet.Open(strFilename, // Filename
true, // Readonly
false, // Untitled
true // WithWindow
));
//*************** How to Run PowerPoint Macros *********************
// Run "ChangeBackColor" macro in the presentation -- note that the
// "ChangeBackColor" macro requires no arguments
{
COleVariant vOpt((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
static BYTE parms[] =
VTS_BSTR VTS_VARIANT;
LPCTSTR lpszMacroName = "Pres.ppt!ChangeBackColor";
oApp.InvokeHelper(0x7e6, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
lpszMacroName, //Macro Name
&vOpt //No arguments, for example, ignore
);
}
// Run "ChangeText" macro in the presentation;
// The macro requires three arguments -- the first two are strings
// and the last one is a long
{
COleSafeArray saArgs; //Create a 1-dimensional array with three
//elements
DWORD numElements[1];
numElements[0]= 3;
saArgs.Create(VT_VARIANT, 1, numElements);
long index[1];
VARIANT v;
index[0]=0; //Fill 1st element
CString sName("ABC");
VariantInit(&v);
v.vt= VT_BSTR;
v.bstrVal = sName.AllocSysString();
saArgs.PutElement(index, &v);
SysFreeString(v.bstrVal);
VariantClear(&v);
index[0]=1; //Fill 2nd element
CString sCompany("XYZ");
VariantInit(&v);
v.vt= VT_BSTR;
v.bstrVal = sCompany.AllocSysString();
saArgs.PutElement(index, &v);
SysFreeString(v.bstrVal);
VariantClear(&v);
index[0]=2; //Fill 3rd element
VariantInit(&v);
v.vt = VT_I4;
v.lVal=123;
saArgs.PutElement(index, &v);
VariantClear(&v);
static BYTE parms[] =
VTS_BSTR VTS_VARIANT;
LPCTSTR lpszMacroName = "Pres.ppt!ChangeText";
oApp.InvokeHelper(0x7e6, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
lpszMacroName, //Macro Name
(VARIANT*)saArgs //Array of macro parameters
);
saArgs.Detach();
}