0

I'm trying to make a piece of code for adding a comment via a shortcut.

I found a macro, but when I run the macro it all seems ok (accurate background highlighting with gray) except that the comment is added only to the last word in the selected group.

Is it possible to have a comment not only for last word in a sentence but for entire selected group of words?

P.S. Is it also possible to take text from clipboard and paste it directly without having to paste it manually (making cursor flashing in commentary, then ctrl+V)? Instead of review this value from a code.

Thank you very much for any help.

Sub Gray()
'
' Gray
'
'
Options.DefaultHighlightColorIndex = wdGray25
Selection.Range.HighlightColorIndex = wdGray25
Selection.Collapse Direction:=wdCollapseEnd
ActiveDocument.Comments.Add _
Range:=Selection.Range, Text:=" review this"
End Sub
YowE3K
  • 23,852
  • 7
  • 26
  • 40
Question
  • 3
  • 2

1 Answers1

0

If you remove Selection.Collapse, the comment will apply to the entire selection.

Suggested new subprocedure:

Sub Gray()

Selection.Range.HighlightColorIndex = wdGray25
Selection.Comments.Add _
Range:=Selection.Range, Text:=" review this"

End Sub

Text from the clipboard can be pulled in by calling a Windows API function. See this previous question for more details.

I recommend using a different shortcut than Ctrl + V to trigger your macro.

davidmneedham
  • 364
  • 1
  • 11
  • Thank you very much. I'm using a different macro key. Thank you agan! Unfortunately, I can't vote for now (15 reps issue). – Question Jul 27 '17 at 08:57
  • If my answer resolved your question, please [accept](https://stackoverflow.com/help/someone-answers) it. – davidmneedham Jul 27 '17 at 18:05