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:resentations> 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:pSaveAsMetaFile,
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."
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:resentations> 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:pSaveAsMetaFile,
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."