1

当我尝试使用变体自动化打开 PowerPoint 文件 (ppt) 时收到此错误消息:

未知名称

我尝试使用自动化:

// 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 没有。

4

1 回答 1

2

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

于 2019-09-01T10:58:05.717 回答