title: Conditional Replace in Word Macro
body: <p>Hi all and thanks in advance for any replies;</p>
  
  <p>This question is about replacing text only under certain conditions.</p>
  
  <p>Background: I'm working on a macro for the editorial department of an academic institution. They get loads of documents that have the same issues and asked for some help to reduce the time they spend on each one.</p>
  
  <p>Two of the things they want:</p>
  
  <ul>
  <li>If a hyphen is between two digits, change it to an en-dash</li>
  <li>Change every ampersand (&amp;) to the word "and"</li>
  </ul>
  
  <p>I have a RegExp that finds and replaces those hyphens just fine, but I noticed a problem. My find/replace changes the "display text" of hyperlinks. Same with ampersands. Bad. So what I'm trying to figure out is how to <strong>exclude</strong> text that has Selection.Style = Word.ActiveDocument.Styles("Hyperlink")</p>
  
  <p>BTW, what's the logical operator for "not equal"? I tried &lt;> and >&lt; but I always get an error telling me that an expression is expected. I'm new to VBA so please forgive the newbie question.</p>
  
  <p>This is working (part of a much larger Sub):</p>
  
  <pre><code>Selection.Find.ClearFormatting
  Selection.Find.Replacement.ClearFormatting
  With Selection.Find
      .Text = "([0-9])-([0-9])"
      .Replacement.Text = "\1" &amp; Chr$(150) &amp; "\2"
      .Forward = True
      .Wrap = wdFindContinue
      .Format = False
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = True
      .MatchSoundsLike = False
      .MatchAllWordForms = False
  End With
  Selection.Find.Execute Replace:=wdReplaceAll
  </code></pre>
  
  <p>So can I create an If/Then statement to tell it to replace only if the style is not hyperlink?</p>
  
  <p>Thanks again,
  Rissa</p>
  
  <p>P.S. I searched for similar posts and found one but it had never been answered. </p>