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

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!
 
J

Jay Freedman

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
 
J

Joanne Christensen

Thanks, Jay, for taking the time to provide the info. I really appreciate
it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top