title: How to extract text between parentheses in window caption in Word macro?
body: <p>I have a scenario where I will have many Word documents with a title that contains text within parentheses which I wish to extract and manipulate. The title bar info (which is not the same as the actual document name) looks something like this:</p>
  
  <p>Random-length text (LAST NAME, FIRST NAME MI) Random-length text</p>
  
  <p>I have experimented with the Left, Right, and Mid functions, but I'm getting mixed results. The only way the Mid function will work is if I determine the exact position and length of the text, but my results have been inconsistent. I can't seem to hone in on JUST the text between the parens - no more, no less.</p>
  
  <p>So far the only success I've had is with two separate macros that work perfectly to get EITHER the text to the left of the right parenthesis OR the text to the right of the left parenthesis. How can I get all of the text in one step?</p>
  
  <hr>
  
  <p>Here are my two "working" macros, FWIW:</p>
  
  <pre><code>Sub a1FullNameDiscardAfterRightParen()
  
  'Discard text after right paren (including paren)
  
    Dim strFullName As String
    Dim BRP As Long 'ARP=after right paren
    strFullName = ActiveDocument.ActiveWindow.Caption
    ARP = InStr(strFullName, Chr(41))
  
    If ARP &gt; 0 Then
       strFullName = Left(strFullName, ARP - 1)
    End If
  
    Selection.TypeText strFullName
  
  End Sub
  --------------------------------------------------------------------------------------
  Sub a2FullNameDiscardBeforeLeftParen()
  
  'Discard text before left paren (including paren)
  
    Dim strFullName As String
    Dim BLP As Long 'BLP=before left paren
    strFullName = ActiveDocument.ActiveWindow.Caption
    BLP = InStr(strFullName, Chr(41))
  
    If BLP &gt; 0 Then
       strFullName = Right(strFullName, BLP - 1)
    End If
  
    Selection.TypeText strFullName
  
  End Sub
  </code></pre>