المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : power point automation.



C++ Programming
04-14-2009, 04:52 PM
Hi,
I have some powerpoint addins which are to be added to powerpoint programmatically.The problem in the below code is it always says power application object cannot be created while running the program. but powerpoint application object will create during debugging the program.
hence I am not able to figure out the problem. Could any one help me please?


void InstallPptAddins(LPCTSTR strAddinPath)
{
CFileFind m_fileFind;
CString strAddin;

PowerPoint::_Application Ppt; //Powerpoint object
PowerPoint::AddIns m_pptAddIns;
PowerPoint::AddIn m_pptAddIn;

if(!Ppt.CreateDispatch("PowerPoint.Application"))
{
Log("Error:fn::InstallPptAddins() Couldn't open Powerpoint Application\n");
return;
}

try
{

if(Ppt.GetVersion()=="12.0")
{
PowerPoint::Presentations m_Sets(Ppt.GetPresentations());
PowerPoint::_Presentation m_Set(m_Sets.Add(TRUE));

strAddin = strAddinPath;
strAddin += "DSAFO5PP.ppa";


if(m_fileFind.FindFile(strAddin))
{
m_pptAddIns = Ppt.GetAddIns();
m_pptAddIn = m_pptAddIns.Add(strAddin);

//Revove first if it already installed
m_pptAddIn.SetLoaded(FALSE);
m_pptAddIn.SetAutoLoad(FALSE);
m_pptAddIn.SetRegistered(FALSE);

//Install the addins
m_pptAddIn.SetLoaded(TRUE);
m_pptAddIn.SetAutoLoad(TRUE);
m_pptAddIn.SetRegistered(TRUE);

Log("AFO Powerpoint add-in is added.\n");

}
else
Log("Couldn't find Powerpoint add-in %s\n",strAddin);


}
catch(...)
{
Log("Error::Couldn't install Powerpoint add-ins.Please add it manually\n\n");
}

Ppt.Quit();
}