title: Saving Excel workbook as PDF gives me an OLE error 800A03EC
body: <p>I have the following function that I want to use for creating a PDF from Excel.
  But when trying to save the PDF I get an OLE error 800A03EC that I simply can't figure out.
  I use the same approach to create PDF from Word and that works just fine. </p>
  
  <pre><code>function xlsCreatePdf(aInput: string; aOutput: string = ''): string;
  var
    FileDoc: OleVariant;
    FilePDF: OleVariant;
    ExcelBook: ExcelWorkbook;
    PdfName: string;
    ExcelApp: ExcelApplication;
  begin
    Result := '';
    if aOutput = '' then
      begin
        PdfName := Folders.DirOutput + ExtractFileName(aInput);
        PdfName := ChangeFileExt(PdfName, '.pdf');
      end
    else
      PdfName := aOutput;
  
    if (Files.Validate(aInput)) then
      begin
        if not Assigned(ExcelApp) then
          ExcelApp := xlsInitialize;
        FileDoc := aInput;
        ExcelBook := ExcelApp.Workbooks.Open(FileDoc,
                                             EmptyParam, EmptyParam, EmptyParam,
                                             EmptyParam, EmptyParam, EmptyParam,
                                             EmptyParam, EmptyParam, EmptyParam,
                                             EmptyParam, EmptyParam, EmptyParam,
                                             EmptyParam, EmptyParam, DefaultLCID);
        FilePdf := PdfName;
        ExcelBook.SaveAs(FilePdf, xlTypePDF,
                         EmptyParam, EmptyParam,
                         False, False,
                         xlNoChange, xlUserResolution, False,
                         EmptyParam, EmptyParam, EmptyParam, DefaultLCID);
        xlsFreeAndNil(ExcelApp);
  
        if (Files.Validate(PdfName)) then
          Result := PdfName
        else
          Result := '';
      end;
  end;
  </code></pre>
  
  <p>I initialize Excel using</p>
  
  <pre><code>function xlsInitialize: ExcelApplication;
  var
    ExcelApp: ExcelApplication;
  begin
    DefaultLCID := LOCALE_USER_DEFAULT;
    ExcelApp := CreateOleObject('Excel.Application') as ExcelApplication;
    if Assigned(ExcelApp) then
      begin
        Result := ExcelApp;
        ExcelApp.Visible[DefaultLCID] := True;
      end
    else
      raise Exception.Create('Cannot initialize Excel application');
  end;
  </code></pre>
  
  <p>And it should be closed using</p>
  
  <pre><code>procedure xlsFreeAndNil(var ExcelApp: ExcelApplication);
  var
    i: integer;
  begin
    if Assigned(ExcelApp) then
      begin
        for i := 0 to ExcelApp.WorkBooks.Count - 1 do
          ExcelApp.WorkBooks.Close(DefaultLCID);
        ExcelApp.Quit;
        Pointer(ExcelApp) := Nil;
      end;
  end;
  </code></pre>
  
  <p>I am using Delphi XE7 and Excel 2010 - the Office TLB used is 2010</p>