Automation of powerpoint

P

Peter Carlson

We use the following code to automate powerpoint to save as windows
metafile. It works just fine on WindowsXP, but on Windows2000 it just
crashes...any idea why? What's especially interesting is the below vbs
works just fine on W2k. Any Ideas would be appreciated! -Peter

bool bRet = true;
::CoInitialize(NULL);
CComPtr<PowerPoint::_Application> app;
if (app.CoCreateInstance(L"Powerpoint.Application", NULL,
CLSCTX_LOCAL_SERVER) == S_OK) {
CComPtr<PowerPoint::presentations> Presentations;
app->get_Presentations(&Presentations);

CComPtr<PowerPoint::_Presentation> Presentation;
CComBSTR bstrFile = csFile.AllocSysString();
if (gDebug & DEBUG_APP) TRACE (this, "CDlgPresentation::Convert",
"[%p] Opening %s", Presentations, csFile);
Presentations->Open(bstrFile, Office::msoFalse, Office::msoTrue,
Office::msoFalse, &Presentation);

CComBSTR bstrOut = csOut.AllocSysString();
if (gDebug & DEBUG_APP) TRACE (this, "CDlgPresentation::Convert",
"Saving %s", csOut);
// Presentation->SaveAs(bstrOut, PowerPoint::ppSaveAsMetaFile,
Office::msoFalse);
app->Quit();
}
else {
if (gDebug & DEBUG_APP) TRACE (this, "CDlgPresentation::Convert",
"Unable to start ppt. %d", GetLastError());
bRet = false;
}
::CoUninitialize();

Dim oPPT
Dim oPPTDoc
Dim sPath
Dim sOutput
sPath= "c:\\chatterbox\Test Presentation.ppt"
sOutput= "c:\\chatterbox"
Set oPPT = WScript.CreateObject("PowerPoint.Application")
' You can comment the line below to keep PowerPoint hidden.
oPPT.Visible = TRUE
Set oPPTDoc=oPPT.Presentations.Open(sPath,False,True,False)
oPPTDoc.Export sOutput,"JPG"
oPPTDoc.Close
Set oPPTDoc = Nothing
oPPT.Quit
set oPPT = Nothing
MsgBox "Export complete."
 
A

Alexander Nickolov

I can only recommend you to ask here:

microsoft.public.office.developer.automation

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: (e-mail address removed)
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
 
P

Peter Carlson

Thanks will do!

Peter

Alexander Nickolov said:
I can only recommend you to ask here:

microsoft.public.office.developer.automation

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: (e-mail address removed)
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Peter Carlson said:
We use the following code to automate powerpoint to save as windows
metafile. It works just fine on WindowsXP, but on Windows2000 it just
crashes...any idea why? What's especially interesting is the below vbs
works just fine on W2k. Any Ideas would be appreciated! -Peter

bool bRet = true;
::CoInitialize(NULL);
CComPtr<PowerPoint::_Application> app;
if (app.CoCreateInstance(L"Powerpoint.Application", NULL,
CLSCTX_LOCAL_SERVER) == S_OK) {
CComPtr<PowerPoint::presentations> Presentations;
app->get_Presentations(&Presentations);

CComPtr<PowerPoint::_Presentation> Presentation;
CComBSTR bstrFile = csFile.AllocSysString();
if (gDebug & DEBUG_APP) TRACE (this, "CDlgPresentation::Convert",
"[%p] Opening %s", Presentations, csFile);
Presentations->Open(bstrFile, Office::msoFalse, Office::msoTrue,
Office::msoFalse, &Presentation);

CComBSTR bstrOut = csOut.AllocSysString();
if (gDebug & DEBUG_APP) TRACE (this, "CDlgPresentation::Convert",
"Saving %s", csOut);
// Presentation->SaveAs(bstrOut, PowerPoint::ppSaveAsMetaFile,
Office::msoFalse);
app->Quit();
}
else {
if (gDebug & DEBUG_APP) TRACE (this, "CDlgPresentation::Convert",
"Unable to start ppt. %d", GetLastError());
bRet = false;
}
::CoUninitialize();

Dim oPPT
Dim oPPTDoc
Dim sPath
Dim sOutput
sPath= "c:\\chatterbox\Test Presentation.ppt"
sOutput= "c:\\chatterbox"
Set oPPT = WScript.CreateObject("PowerPoint.Application")
' You can comment the line below to keep PowerPoint hidden.
oPPT.Visible = TRUE
Set oPPTDoc=oPPT.Presentations.Open(sPath,False,True,False)
oPPTDoc.Export sOutput,"JPG"
oPPTDoc.Close
Set oPPTDoc = Nothing
oPPT.Quit
set oPPT = Nothing
MsgBox "Export complete."
 

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