Group:  Microsoft Word ยป microsoft.public.word.docmanagement
Thread: Adding user's selected text as new item in listbox.

Geek News

Adding user's selected text as new item in listbox.
Joanne Christensen 12/21/2008 3:36:23 PM
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!
Re: Adding user's selected text as new item in listbox.
Jay Freedman <jay.freedman[ at ]verizon.net> 12/21/2008 4:07:29 PM
On Sun, 21 Dec 2008 07:36:23 -0800, Joanne Christensen <Joanne
Christensen[ at ]discussions.microsoft.com> wrote:

[Quoted Text]
>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


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
Re: Adding user's selected text as new item in listbox.
Joanne Christensen 12/21/2008 4:23:01 PM
Thanks, Jay, for taking the time to provide the info. I really appreciate
it.

"Jay Freedman" wrote:

[Quoted Text]
> On Sun, 21 Dec 2008 07:36:23 -0800, Joanne Christensen <Joanne
> Christensen[ at ]discussions.microsoft.com> wrote:
>
> >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
>
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net