How to use PowerPoint Automation in C++ Builder?

322 views Asked by At

I get this error message when i try to open PowerPoint file (ppt) using Variant automation:

Unknown Name

I tried using Automation:

// 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);

}

This code gives me the error above. Note: PowerPoint opens without any errors in the background, but the ppt doesn't.

1

There are 1 answers

2
maksim_volodin On BEST ANSWER

This error occurs when the property, function or method which you refer does not exist. Application object does not have Enabled property MSDN. To open ppt you should use WideString type for ppt_filename because this type is compatible with BSTR type used with COM objects or you should use StringToOleStr().