Adding user's selected text as new item in listbox.

  • Thread starter Thread starter Joanne Christensen
  • Start date Start date
J

Joanne Christensen

I am trying to create a macro that would take whatever text has been
highlighted in a Word Document by the user and then add it on the fly to a
list box on a modeless form. The part that I am having trouble is somehow
capturing the contents of the selected text so I can make mytext in the
ListBox1.AddItem (mytext) be the highlighted text. I am lost at the present
time trying to sort out using range and selection. If there is anyone who
could help me with me, I would really appreciate it. Thanks!
 
On Sun, 21 Dec 2008 07:36:23 -0800, Joanne Christensen <Joanne
I am trying to create a macro that would take whatever text has been
highlighted in a Word Document by the user and then add it on the fly to a
list box on a modeless form. The part that I am having trouble is somehow
capturing the contents of the selected text so I can make mytext in the
ListBox1.AddItem (mytext) be the highlighted text. I am lost at the present
time trying to sort out using range and selection. If there is anyone who
could help me with me, I would really appreciate it. Thanks!

The code you're looking for is

mytext = Selection.Text
ListBox1.AddItem mytext

or, if you don't need to use the variable mytext for something else, simply use

ListBox1.AddItem Selection.Text
 
Thanks, Jay, for taking the time to provide the info. I really appreciate
it.
 
Back
Top