title: How do I use the Microsoft Word API and Bookmarks feature to programmatically open a Word document to a specific location?
body: <p>I'm trying the following code in a Windows Form application. I'm not sure what I'm doing wrong (and I could easily be doing it wrong because I don't have a lot of experience with the Word API) but the GoTo command just cannot find the bookmark. I always get a COMException on the last line, "This bookmark does not exist."</p>
  
  <p>But the <code>wordDoc.Bookmarks.get_Item(ref name)</code> method does find the bookmark! <strong>What gives?</strong> </p>
  
  <pre><code>Object fileName = System.Windows.Forms.Application.StartupPath + "\\Bookmarks.docx";
  Object readOnly = false;
  Object isVisible = true;
  Object missing = System.Reflection.Missing.Value;
  
  Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
  Microsoft.Office.Interop.Word.Document wordDoc = new Microsoft.Office.Interop.Word.Document();
  
  wordApp.Visible = true;
  wordDoc = wordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);
  
  Object item = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToBookmark;
  Object whichitem = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToFirst;
  Object count = 1;
  Object name = "Location3";
  
  Bookmark bMark = wordDoc.Bookmarks.get_Item(ref name);
  wordDoc.GoTo(ref item, ref whichitem, ref count, ref name);
  </code></pre>