title: Microsoft Word - Insert text from JavaScript/JScript ActiveX
body: <p>I want to use JavaScript (on a web page) to insert some text into a Microsoft Word document.  <a href="http://msdn.microsoft.com/en-us/library/6b9478cs%28v=VS.100%29.aspx#Y1938" rel="nofollow">The Documentation</a> has sample code for VB and C#, but not for JavaScript (JScript).  I've been able to figure out a lot of it using code samples <a href="http://msdn.microsoft.com/en-us/library/7sw4ddf8%28v=VS.85%29.aspx" rel="nofollow">as seen here</a>, but certain lines are messing me up.</p>
  
  <p>Here's what I've got so far:</p>
  
  <p>var retText;</p>
  
  <pre><code>var wshShell = new ActiveXObject("WScript.Shell");
  var wordApp = new ActiveXObject("Word.Application");
  wordApp.Documents.Add();
  
  if (wordApp.Application.Options.Overtype) {
      wordApp.Options.Overtype = false;
  }
  </code></pre>
  
  <p>But when it comes to this line (in C#), I can't quite get at how to translate it:</p>
  
  <pre><code>if (currentSelection.Type == Word.WdSelectionType.wdSelectionIP) 
  </code></pre>
  
  <p><code>currentSelection.Type</code> can be translated to <code>wordApp.Selection.Type</code> in my code above, but I'm not sure what to do with <code>Word.WdSelectionType.wdSelectionIP</code>.</p>
  
  <p>Some failed attempts:</p>
  
  <pre><code>alert(wordApp.WdSelectionType); //undefined
  alert(new ActiveXObject("Word.WdSelectionType"); //errors out
  alert(wordApp.ActiveDocument.WdSelectionType); //undefined    
  </code></pre>