title: Macro to insert comments on keywords in selected text in a Word doc?
body: <p>I'm new to VBA and would greatly appreciate some help on a problem. </p>
  
  <p>I have long Word documents where I need to apply standard comments to the same set of keywords, but only in selected sections of the document. The following macro worked to find a keyword and apply a comment (from question here <a href="https://superuser.com/questions/547710/macro-to-insert-comment-bubbles-in-microsoft-word">https://superuser.com/questions/547710/macro-to-insert-comment-bubbles-in-microsoft-word</a>): </p>
  
  <pre><code>Sub label_items()
  '
  ' label_items Macro
  '
  '
  Do While Selection.Find.Execute("keyword1") = True
      ActiveDocument.Comments.Add range:=Selection.range, Text:="comment for keyword 1"
  Loop
  
  End Sub
  </code></pre>
  
  <p>The two modifications are:</p>
  
  <p>1) only apply the comments to user selected text, not the whole document. I tried a "With Selection.Range.Find" approach but I don't think comments can be added this way (??)</p>
  
  <p>2) repeat this for 20+ keywords in the selected text. The keywords aren't totally standard and have names like P_1HAI10, P_1HAI20, P_2HAI60, P_HFS10, etc. </p>
  
  <p>EDIT: I have tried to combine code from similar questions (  <a href="https://stackoverflow.com/questions/37881513/word-vba-finding-a-set-of-words-and-inserting-predefined-comments?rq=1">Word VBA: finding a set of words and inserting predefined comments</a> and <a href="https://stackoverflow.com/questions/1000582/word-macro-storing-the-current-selection-vba">Word macro, storing the current selection (VBA)</a>) but my current attempt (below) only runs for the first keyword and comment and runs over the entire document, not just the text I have highlighted/selected. </p>
  
  <pre><code>Sub label_items()
  '
  ' label_items Macro
  '
  Dim selbkup As range
  Set selbkup = ActiveDocument.range(Selection.range.Start, Selection.range.End)
  
  Set range = selbkup
  
  Do While range.Find.Execute("keyword 1") = True
      ActiveDocument.Comments.Add range, "comment for keyword 1"
  Loop
  
  Set range = selbkup
  
  Do While range.Find.Execute("keyword 2") = True
      ActiveDocument.Comments.Add range, "comment for keyword 2"
  Loop
  
  'I would repeat this process for all of my keywords
  
  End Sub
  </code></pre>
  
  <p>I've combed through previous questions and the Office Dev Center and am stuck. Any help/guidance is greatly appreciated!</p>