title: MS Word + VBA + RegExp: Get Page Number of Match
body: <p>Is that possible? Probably not? How can I then find all exact occurrences of a match and the according page numbers?</p>
  
  <p>EDIT:</p>
  
  <p>I have the regex working properly. What I need is for each match to get all the pages it appears on.</p>
  
  <p>Example:</p>
  
  <pre><code>regex = \b\d{3}\b
  
  123 appears on page 1,4,20
  243 appear on page 3,5,7
  523 appears on page 9
  </code></pre>
  
  <p>How can I get that information (all the pages a match occurs on?)</p>
  
  <p>This is for creating some kind of index automatically.</p>
  
  <p>EDIT 2:</p>
  
  <p>I got a basic working version, snippet:</p>
  
  <pre><code>Set Matches = regExp.Execute(ActiveDocument.range.Text)
  
  For Each Match In Matches    
      Set range = ActiveDocument.range(Match.FirstIndex, Match.FirstIndex + Len(Match.Value))    
      page = range.Information(wdActiveEndAdjustedPageNumber)
  </code></pre>
  
  <p>The problem is that Match.FirstIndex does not always point to the first character of the match in ActiveDocument.range. Word tables mess this up as ActiveDocument.range.Text contains characters that are not on the text put represent something in the table.</p>