首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在PowerPoint生成器中使用C++自动化?

如何在PowerPoint生成器中使用C++自动化?
EN

Stack Overflow用户
提问于 2019-08-31 13:41:59
回答 1查看 254关注 0票数 1

当我试图使用变体自动化打开PowerPoint文件(ppt)时,会收到以下错误消息:

未知名称

我试过使用自动化:

代码语言:javascript
复制
// Open PPT File
void TMainForm::OpenPPTFile(UnicodeString APPTFile)
{

    UnicodeString ppt_path = ExtractFilePath(Application->ExeName)+"ppt\\";
    UnicodeString ppt_filename = ppt_path+APPTFile;
    Variant PowerPoint;

    if ( !DirectoryExists(ppt_path) )
    {
        Application->MessageBoxW(L"The specified Directory does't exist!", L"Error", MB_OK);
        return;
    }

    if ( !FileExists(ppt_filename) )
    {
        Application->MessageBoxW(L"The specified File does't exist!", L"Error", MB_OK);
        return;
    }

    PowerPoint = CreateOleObject("PowerPoint.Application");

    if ( PowerPoint.IsEmpty() )
    {
        Application->MessageBoxW(L"Unable to open Powerpoint, please check if installed!", L"Error", MB_OK);
        return;
    }

    PowerPoint.OlePropertySet("Enabled", true);
    PowerPoint.OlePropertySet("Visible", true);
    PowerPoint.OlePropertyGet("Presentations").OleProcedure("Open", ppt_filename, false, false, true);

}

这段代码给出了上面的错误。注意: PowerPoint在后台没有任何错误的情况下打开,但是ppt没有。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-01 10:58:05

当您所引用的属性、函数或方法不存在时,会发生此错误。Application对象没有Enabled属性MSDN。要打开ppt,您应该为ppt_filename使用WideString类型,因为这种类型与COM对象使用的BSTR类型兼容,或者您应该使用StringToOleStr()

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57738516

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档