Re: Get selected text in VBA
you could try copying the selection, then retrieve the text from the clipboard
Re: Get selected text in VBA
There is very little that can be done with discontiguous selections without doing a bit of hackery type coding.
See: Limited programmatic access to Word discontiguous selections
With that stated, one method is to set a unique format on the Selection and then search for that format. I chose to set the Font Size to 1.
Code:
Selection.Font.Size = 1
Dim foundText As New Collection ' to store the individual selections
Dim searchRange As Word.Range
Set searchRange = ActiveDocument.Range
With searchRange.find
.ClearFormatting
.Font.Size = 1
.Format = True
.Execute
Do While .Found
foundText.Add searchRange.Text
.Execute
Loop
End With
ActiveDocument.Undo ' undo Font.Size = 1
Dim txt As Variant
For Each txt In foundText
Debug.Print txt
Next txt
Re: Get selected text in VBA
i tested my previous suggestion, like
Code:
set myclip = createobject("Clipbrd.Clipboard")
myclip.clear
selection.copy
debug.print myclip.gettext
use your own method to access the clipboard, you can use a dataobject or APIs, else checkout
http://www.vbforums.com/showthread.php?t=585616