<FONT face=Courier><FONT color=#0000ff>public void </FONT><FONT color=#000000>CheckRuntime() {</FONT>
<FONT color=#0000ff>object </FONT><FONT color=#000000>reference = </FONT><FONT color=#0000ff>null</FONT><FONT color=#000000>;</FONT>
<FONT color=#0000ff>try </FONT><FONT color=#000000>{</FONT>
<FONT color=#000000>reference = </FONT><FONT color=#808000>Marshal</FONT><FONT color=#000000>.GetActiveObject(</FONT><FONT color=#ff00ff>"Word.Application"</FONT><FONT color=#000000>);</FONT>
<FONT color=#000000>}</FONT>
<FONT color=#0000ff>catch </FONT><FONT color=#000000>(</FONT><FONT color=#808000>COMException</FONT><FONT color=#000000>) {</FONT>
<FONT color=#008080>System</FONT><FONT color=#000000>.</FONT><FONT color=#808000>Console</FONT><FONT color=#000000>.Out.WriteLine(</FONT><FONT color=#ff00ff>"No instances found..."</FONT><FONT color=#000000>);</FONT>
<FONT color=#000000>}</FONT>
<FONT color=#0000ff>if </FONT><FONT color=#000000>(reference != </FONT><FONT color=#0000ff>null</FONT><FONT color=#000000>) {</FONT>
<FONT color=#0000ff>try </FONT><FONT color=#000000>{</FONT>
<FONT color=#008080>System</FONT><FONT color=#000000>.</FONT><FONT color=#808000>Console</FONT><FONT color=#000000>.Out.WriteLine(</FONT><FONT color=#ff00ff>"Found running instance!"</FONT><FONT color=#000000>);</FONT>
<FONT color=#000000>ApplicationClass wordRuntime = (ApplicationClass)reference;</FONT>
<FONT color=#008080>System</FONT><FONT color=#000000>.</FONT><FONT color=#008080>Text</FONT><FONT color=#000000>.</FONT><FONT color=#808000>StringBuilder </FONT><FONT color=#000000>buffer = </FONT><FONT color=#0000ff>new </FONT><FONT color=#808000>StringBuilder</FONT><FONT color=#000000>();</FONT>
<FONT color=#0000ff>foreach </FONT><FONT color=#000000>(Document document </FONT><FONT color=#0000ff>in </FONT><FONT color=#000000>wordRuntime.Documents) {</FONT>
<FONT color=#000000>buffer.AppendFormat(</FONT><FONT color=#ff00ff>"{0}|"</FONT><FONT color=#000000>, document.Name);</FONT>
<FONT color=#0000ff>if </FONT><FONT color=#000000>(wordRuntime.Selection != </FONT><FONT color=#0000ff>null</FONT><FONT color=#000000>) {</FONT>
<FONT color=#008080>System</FONT><FONT color=#000000>.</FONT><FONT color=#808000>Console</FONT><FONT color=#000000>.Out.WriteLine(</FONT><FONT color=#ff00ff>"Selected text: \"{0}\""</FONT><FONT color=#000000>,</FONT>
<FONT color=#000000>wordRuntime.Selection.</FONT><FONT color=#008080>Text</FONT><FONT color=#000000>);</FONT>
<FONT color=#0000ff>object </FONT><FONT color=#000000>optional = </FONT><FONT color=#808000>Missing</FONT><FONT color=#000000>.Value;</FONT>
<FONT color=#0000ff>object </FONT><FONT color=#000000>url = </FONT><FONT color=#ff00ff>"http://www.google.com/"</FONT><FONT color=#000000>;</FONT>
<FONT color=#0000ff>if</FONT><FONT color=#000000>(wordRuntime.Selection.Hyperlinks.Count == </FONT><FONT color=#800080>0</FONT><FONT color=#000000>) {</FONT>
<FONT color=#000000>wordRuntime.Selection.Hyperlinks._Add(</FONT>
<FONT color=#000000>wordRuntime.Selection.Range,</FONT>
<FONT color=#0000ff>ref </FONT><FONT color=#000000>url,</FONT>
<FONT color=#0000ff>ref </FONT><FONT color=#000000>optional</FONT>
<FONT color=#000000>);</FONT>
<FONT color=#000000>}</FONT>
<FONT color=#000000>}</FONT>
<FONT color=#000000>}</FONT>
<FONT color=#008080>System</FONT><FONT color=#000000>.</FONT><FONT color=#808000>Console</FONT><FONT color=#000000>.Out.WriteLine(</FONT>
<FONT color=#0000ff>string</FONT><FONT color=#000000>.Format(</FONT><FONT color=#ff00ff>"Currently open documents are: {0}"</FONT><FONT color=#000000>,</FONT>
<FONT color=#000000>buffer.ToString().Trim(</FONT><FONT color=#ff00ff>'|'</FONT><FONT color=#000000>))</FONT>
<FONT color=#000000>);</FONT>
<FONT color=#000000>}</FONT>
<FONT color=#0000ff>finally </FONT><FONT color=#000000>{</FONT>
<FONT color=#808000>Marshal</FONT><FONT color=#000000>.ReleaseComObject(reference);</FONT>
<FONT color=#000000>}</FONT>
<FONT color=#000000>}</FONT>
<FONT color=#000000>}</FONT>
</FONT>