 <p>You may be looking for</p> <pre><code>Document doc = DTE.ActiveDocument; TextDocument txt = doc.Object() as TextDocument; </code></pre> <p>You should then be able to edit work with the TextDocument as needed.</p>