title: COM('word.document') open in read only whilst file is opened by other
body: <p>I'm using php and try to fiddle around with COM objects to read Word files. I am getting litereally nowhere with finding documentation.</p>
  
  <p>What I want to do is open a file in read only so I dont get the "File is in use" popup on the host computer.</p>
  
  <p>How do I tell word via COM to open the file as read only? I am trying to use variants but I get the following error:</p>
  
  <p><code>Parameter 0: Type mismatch. #0 C:\xampp\htdocs\test.php(17): variant-&gt;Open('\\remote\test\test.doc', false, true, false, Object(variant), Object(variant), Object(variant), Object(variant), Object(variant), Object(variant), Object(variant), true, true, Object(variant), Object(variant), true) #1 {main}</code></p>
  
  <p>This is the code I use</p>
  
  <pre><code>$word = new COM("word.application") or die("Unable to instantiate application object");
  
  $wordDocument = new COM("word.document") or die("Unable to instantiate document object");
  $MISSING =  new VARIANT();
  
  $word-&gt;Visible = 0;
  $DocumentPath = "\\remote\test\test\alamo.doc";
  $HTMLPath = "";
  try {
  $wordDocument = $word-&gt;Documents-&gt;Open("\\exit-dc\eeb\test\alamo.doc"/* FileName */, false/* ConfirmConversions */, true/* ReadOnly */, 
                                      false/* AddToRecentFiles */, $MISSING/* PasswordDocument */, $MISSING/* PasswordTemplate */, 
                                      $MISSING/* Revert */, $MISSING/* WritePasswordDocument */, $MISSING/* WritePasswordTemplate */, 
                                      $MISSING/* Format */,$MISSING/* Format */, $MISSING/* Encoding */, true/* Visible */, true/* OpenConflictDocument */, 
                                      $MISSING/* OpenAndRepair */, $MISSING/* DocumentDirection */, true/* NoEncodingDialog */);
  
  $HTMLPath = substr_replace($DocumentPath, 'html', -3, 3);
  if($wordDocument !== null) {
      $wordDocument-&gt;SaveAs($HTMLPath, 3);//3 = text, I know.
  }
  }
  catch(Exception $ex){
      echo $ex-&gt;getMessage() . $ex-&gt;getTraceAsString();
  }
  $wordDocument = null;
  
  $word-&gt;Quit();
  
  $word = null;
  </code></pre>
  
  <p>What i want? To open the file with the read only flag. I only want to read from it. I know I can do that by providing the filename only, that works, but I need it to work with multiple instances reading the same file.</p>
  
  <p>For all intents and purposes this should work. Php should cast the string and booleans to the proper Variant types and the empty variant types should fill the place of <code>System.Reflection.Missing.Value</code></p>
  
  <p>I used <a href="https://msdn.microsoft.com/en-us/library/office/ff835182(v=office.14).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/office/ff835182(v=office.14).aspx</a> (Word 2010) to compile the list of arguments needed, and reading through the comments on <a href="http://php.net/manual/en/book.com.php" rel="nofollow">http://php.net/manual/en/book.com.php</a> to find a workable solution... </p>
  
  <p>The only solution that seems to work so far is making a copy, open that, read it, delete the copy. For me thats the least desirable option because this should you know, work. Plenty of C++, vb, .net etc... examples of how this works, but php simply refuses to accept the parameters. What am i doing wrong?</p>