title: How to make Word invisible during OLE automation from Delphi
body: <p>From our application we use OLE automation to build a fairly complex Word-document. I would like to make Word invisible while the document is being made, since there is a lot of pasting and insertions that takes quite a long time. </p>
  
  <p>I use the following code to establish a Word connection:</p>
  
  <pre><code>function ConnectToWord : TWordAutomationResult;
  begin
    WordApp := TWordApplication.Create(nil);
  
    try
      WordApp.Connect;
      WordApp.Visible := false; 
    except on E: Exception do
      begin
        Result := waeErrorConnectingToWord;
        exit;
      end;
    end;
  end;      
  </code></pre>
  
  <p>And I use the following code to open an existing document, which is then edited by my application.</p>
  
  <pre><code>function TWordAUtomation.OpenDocument(aFileName: string) : WordDocument;
  var vFileName,
      vConfirmConversions,
      vReadOnly,
      vAddToRecentFiles,
      vPasswordDocument,
      vPasswordTemplate,
      vRevert,
      vWritePasswordDocument,
      vWritePasswordTemplate,
      vFormat,
      vEncoding,
      vVisible,
      vOpenConflictDocument,
      vOpenAndRepair,
      vWdDocumentDirection,
      vNoEncodingDialog  : OleVariant;
  begin
    Result := nil;
    if not FileExists(aFileName) then exit;
  
    vFileName                := aFileName;
    vConfirmConversions      := True;
    vReadOnly                := False;
    vAddToRecentFiles        := False;
    vPasswordDocument        := EmptyParam;
    vPasswordTemplate        := EmptyParam;
    vRevert                  := True; 
    vWritePasswordDocument   := EmptyParam;
    vWritePasswordTemplate   := EmptyParam;
    vFormat                  := wdOpenFormatAuto;
    vEncoding                := EmptyParam;
    vVisible                 := False; //Document should be invisible
    vOpenConflictDocument    := EmptyParam;
    vOpenAndRepair           := EmptyParam;
    vWdDocumentDirection     := EmptyParam;
    vNoEncodingDialog        := EmptyParam;
  
    Result := WordApp.Documents.Open(vFileName, vConfirmConversions, vReadOnly, vAddToRecentFiles, vPasswordDocument, vPasswordTemplate, vRevert, vWritePasswordDocument, vWritePasswordTemplate, vFormat, vEncoding, vVisible, vOpenAndRepair, vWdDocumentDirection, vNoEncodingDialog);
  end;
  </code></pre>
  
  <p>It works on my computer! (TM)</p>
  
  <p>For some of our customers Word remains visible during the editing process. What reasons can there be for this? As far as I can tell the problem arises for customers that use some sort of remote computing, like managed clients etc. Are there some additional properties that deals with application visibility that only have effect during remote desktop connections etc? I'm not very knowledgeable about such things :-(</p>