当我试图使用变体自动化打开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没有。
发布于 2019-09-01 10:58:05
当您所引用的属性、函数或方法不存在时,会发生此错误。Application对象没有Enabled属性MSDN。要打开ppt,您应该为ppt_filename使用WideString类型,因为这种类型与COM对象使用的BSTR类型兼容,或者您应该使用StringToOleStr()。
https://stackoverflow.com/questions/57738516
复制相似问题