Jump to content

OLE with Word doesnt work ..


erich.wanker

Recommended Posts

Hi .. has someone a idea why this simple OLE doesnt work? (the paths and Files are correct) in my hyperserver-hosted unigui-dll

( is it a user right thing??   .. the apache webserver is running as "local System" ...)

 

ThanX

Erich

 

uses ComObj, Variants
var: WordApplication, WordFile : OleVariant;
...
          WordApplication := Null;
          WordFile := Null;

          try
            // create Word OLE
            try
              // Check if Word is already opened?
              WordApplication := GetActiveOleObject('Word.Application' );
            except
              try
                WordApplication := CreateOleObject('Word.Application' );
                WordApplication.Visible := true;
              except
                Exception.Create( 'Error' );
              end;
            end;

          except
            WordApplication := Null;
          end;

          If VarIsNull( WordApplication ) = False
          then
          begin
            try
              WordApplication.Visible := true;
              WordApplication.DisplayAlerts := true; 

              // Open Word File
              try
                WordFile := WordApplication.Documents.Open(merge_dateiname_mit_pfad );
              except
                WordFile := Null;
              end;

              If VarIsNull( WordFile ) = False
              then
              begin
                WordFile.SaveAs2( merge_destfolder + '\aenderung' + UniMainModule.Z_AENDERUNG.FieldByName( 'Reportnummer' ).AsString + '\converted.pdf', 17 ); // wdFormatPDF = 17
              end
              else
              begin
                showtoast('Word-Dok not saved');
              end;
            finally
              WordFile.Close;
              WordApplication.DisplayAlerts := true;
              WordApplication.Quit;
              WordFile := Unassigned;
              WordApplication := Unassigned;
            end;
          end
          else
          begin
            showtoast('Word Application not started');
          end;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...