title: Visual Studio - How to disable autoformat/correct while running macro?
body: <p>When running a macro that changes the selected text, tags are automatically closed and the text formatted. How can I prevent that from happening?</p>
  
  <p>For example, wrapping text in a tag:</p>
  
  <pre><code>DTE.ActiveDocument.Selection.Text = String.Format("&lt;tag&gt;{0}&lt;/tag&gt;", DTE.ActiveDocument.Selection.Text)
  </code></pre>
  
  <p>Ends up with two closing tags:</p>
  
  <pre><code>&lt;tag&gt;Text&lt;/tag&gt;&lt;/tag&gt;
  </code></pre>
  
  <p>Even stranger, multiple lines fails:</p>
  
  <pre><code>&lt;li&gt;One&lt;/li&gt;
  &lt;li&gt;Two&lt;/li&gt;
  &lt;li&gt;Three&lt;/li&gt;
  </code></pre>
  
  <p>An ends up as</p>
  
  <pre><code>&lt;ul&gt;            &lt;li&gt;One&lt;/li&gt;
              &lt;li&gt;Two&lt;/li&gt;
                          &lt;li&gt;Three&lt;/li&gt;&lt;/li&gt;&lt;/ul&gt;
  </code></pre>
  
  <p>How can I prevent that? As can be seen by the last example, the formatting is wrong and there is an extra <code>&lt;/li&gt;</code></p>