Insert Autotext Entries in a Document 
Author Message
 Insert Autotext Entries in a Document

Hi,

I have 20 autotext entries in a template. I have defined a listbox
(fmListStyleOption) in a userform and populated the listbox with the
autotext entries.

I need to know the best way to insert the selected autotext entries from the
listbox into the document. should I use bookmarks for each and every
autotext entry in the main document? Also providing me with a sample code
for the "OK" button to insert each checked autotext entry from the listbox
into the document will be highly appreciated.

Thanks in advance.

Raja



Mon, 28 Nov 2005 14:49:24 GMT  
 Insert Autotext Entries in a Document



Quote:
> Hi,

> I have 20 autotext entries in a template. I have defined a listbox
> (fmListStyleOption) in a userform and populated the listbox with the
> autotext entries.

> I need to know the best way to insert the selected autotext entries from
the
> listbox into the document. should I use bookmarks for each and every
> autotext entry in the main document?

That depends on where in the document you want the autotext entries to go.
There's no general "best" way of doing this, it depends entirely on the
individual case. Do whatever works for your document. If the simplest way of
identifying where the entries should go is to mark the places with
bookmarks, then that is a perfectly valid approach.

Quote:
> Also providing me with a sample code
> for the "OK" button to insert each checked autotext entry from the listbox
> into the document will be highly appreciated.

This code should put you on the right track.

For i = 0 to ListBox1.ListCount - 1
    If ListBox1.Selected(i) Then
        'This item is selected, get the name of the entry
        strAutoTextName = ListBox1.List(i, 0)

        ' Your code here to insert the Autotext

    End If
Next i

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email



Mon, 28 Nov 2005 16:05:37 GMT  
 Insert Autotext Entries in a Document
Hi Raja,

If each autotext entry needs to go into a specific location, then placing a
bookmark at the respective locations is probably what you will have to do.

The following code will insert the autotext entry "rand" at the location of
a bookmark named "test" in the active document:

ActiveDocument.AttachedTemplate.AutoTextEntries("rand").Insert _
    Where:=ActiveDocument.Bookmarks("Test").Range, RichText:=True

To determine which autotext entries are selected in the Listbox, use the
procedure in the article How to find out which Items are selected in a
Multi-Select ListBox at:

http://www.mvps.org/word/FAQs/Userforms/GetMultiSelectValues.htm

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP


Quote:
> Hi,

> I have 20 autotext entries in a template. I have defined a listbox
> (fmListStyleOption) in a userform and populated the listbox with the
> autotext entries.

> I need to know the best way to insert the selected autotext entries from
the
> listbox into the document. should I use bookmarks for each and every
> autotext entry in the main document? Also providing me with a sample code
> for the "OK" button to insert each checked autotext entry from the listbox
> into the document will be highly appreciated.

> Thanks in advance.

> Raja



Mon, 28 Nov 2005 16:23:45 GMT  
 Insert Autotext Entries in a Document
Hi Jonathan,

Thanks a lot for your reply and Doug's.

I have inserted a bookmark called "Insert" in my template where the selected
autotext entries should go.  I don't care about the order or the location
where the entries go as long as they all get inserted in a specific place in
the document. I tried to complete the code to insert the text in the
document without succeeding. Consulting the VBA help only added to my
confusion.

You are kindly requested to give me the syntax of the "insert" method to use
to insert "strAutoTextName" entry into the document.

I can't thank you enough.

Raja


Quote:



> > Hi,

> > I have 20 autotext entries in a template. I have defined a listbox
> > (fmListStyleOption) in a userform and populated the listbox with the
> > autotext entries.

> > I need to know the best way to insert the selected autotext entries from
> the
> > listbox into the document. should I use bookmarks for each and every
> > autotext entry in the main document?

> That depends on where in the document you want the autotext entries to go.
> There's no general "best" way of doing this, it depends entirely on the
> individual case. Do whatever works for your document. If the simplest way
of
> identifying where the entries should go is to mark the places with
> bookmarks, then that is a perfectly valid approach.

> > Also providing me with a sample code
> > for the "OK" button to insert each checked autotext entry from the
listbox
> > into the document will be highly appreciated.

> This code should put you on the right track.

> For i = 0 to ListBox1.ListCount - 1
>     If ListBox1.Selected(i) Then
>         'This item is selected, get the name of the entry
>         strAutoTextName = ListBox1.List(i, 0)

>         ' Your code here to insert the Autotext

>     End If
> Next i

> --
> Regards
> Jonathan West - Word MVP
> MultiLinker - Automated generation of hyperlinks in Word
> Conversion to PDF & HTML
> http://www.multilinker.com
> Word FAQs at http://www.multilinker.com/wordfaq
> Please post any follow-up in the newsgroup. I do not reply to Word
questions
> by email



Mon, 28 Nov 2005 20:36:41 GMT  
 Insert Autotext Entries in a Document



Quote:
> Hi Jonathan,

> Thanks a lot for your reply and Doug's.

> I have inserted a bookmark called "Insert" in my template where the
selected
> autotext entries should go.  I don't care about the order or the location
> where the entries go as long as they all get inserted in a specific place
in
> the document. I tried to complete the code to insert the text in the
> document without succeeding. Consulting the VBA help only added to my
> confusion.

> You are kindly requested to give me the syntax of the "insert" method to
use
> to insert "strAutoTextName" entry into the document.

Hi Raja

Try this

This code should be at the start of the routine somewhere outside the loop,
but after you have opened the target document

   Dim myRange as Range
   Set myRange = ActiveDocument.Bookmarks("Insert").Range

This code goes in the loop

   ActiveDocument.AttachedTemplate.AutoTextEntries(strAutoTextName).Insert _
       Where:=myRange, RichText:=True
   myRange.Collapse Direction:=wdCollapseEnd

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email



Mon, 28 Nov 2005 21:43:25 GMT  
 Insert Autotext Entries in a Document
Have you looked into the AutoTextList field? See "How to add pop-up lists to
any Word document so you can click your way through changes in seconds." at
<URL: http://www.mvps.org/word/FAQs/TblsFldsFms/AutoTextList.htm>.
--
Charles Kenyon

Word New User FAQ & Web Directory:
<URL: http://www.addbalance.com/word/index.htm>

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide)
<URL: http://www.addbalance.com/usersguide/index.htm>

Word Resources Page
<URL: http://www.addbalance.com/word/wordwebresources.htm>

See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
 --------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.



Quote:
> Hi,

> I have 20 autotext entries in a template. I have defined a listbox
> (fmListStyleOption) in a userform and populated the listbox with the
> autotext entries.

> I need to know the best way to insert the selected autotext entries from
the
> listbox into the document. should I use bookmarks for each and every
> autotext entry in the main document? Also providing me with a sample code
> for the "OK" button to insert each checked autotext entry from the listbox
> into the document will be highly appreciated.

> Thanks in advance.

> Raja



Tue, 29 Nov 2005 00:26:37 GMT  
 Insert Autotext Entries in a Document
Thanks a lot Jonathan. You have been a great help.

Raja


Quote:



> > Hi Jonathan,

> > Thanks a lot for your reply and Doug's.

> > I have inserted a bookmark called "Insert" in my template where the
> selected
> > autotext entries should go.  I don't care about the order or the
location
> > where the entries go as long as they all get inserted in a specific
place
> in
> > the document. I tried to complete the code to insert the text in the
> > document without succeeding. Consulting the VBA help only added to my
> > confusion.

> > You are kindly requested to give me the syntax of the "insert" method to
> use
> > to insert "strAutoTextName" entry into the document.

> Hi Raja

> Try this

> This code should be at the start of the routine somewhere outside the
loop,
> but after you have opened the target document

>    Dim myRange as Range
>    Set myRange = ActiveDocument.Bookmarks("Insert").Range

> This code goes in the loop

>    ActiveDocument.AttachedTemplate.AutoTextEntries(strAutoTextName).Insert
_
>        Where:=myRange, RichText:=True
>    myRange.Collapse Direction:=wdCollapseEnd

> --
> Regards
> Jonathan West - Word MVP
> MultiLinker - Automated generation of hyperlinks in Word
> Conversion to PDF & HTML
> http://www.multilinker.com
> Word FAQs at http://www.multilinker.com/wordfaq
> Please post any follow-up in the newsgroup. I do not reply to Word
questions
> by email



Tue, 29 Nov 2005 21:55:14 GMT  
 Insert Autotext Entries in a Document
Hi Charles,

I prefer the VBA solution as the the user can select multiple paragraphs to
insert, not a signle paragraph from a list of choices.

Thanks anyway.

Raja



Quote:
> Have you looked into the AutoTextList field? See "How to add pop-up lists
to
> any Word document so you can click your way through changes in seconds."
at
> <URL: http://www.mvps.org/word/FAQs/TblsFldsFms/AutoTextList.htm>.
> --
> Charles Kenyon

> Word New User FAQ & Web Directory:
> <URL: http://www.addbalance.com/word/index.htm>

> Intermediate User's Guide to Microsoft Word (supplemented version of
> Microsoft's Legal Users' Guide)
> <URL: http://www.addbalance.com/usersguide/index.htm>

> Word Resources Page
> <URL: http://www.addbalance.com/word/wordwebresources.htm>

> See also the MVP FAQ: <URL: http://www.mvps.org/word/> which is awesome!
>  --------- --------- --------- --------- --------- ---------
> This message is posted to a newsgroup. Please post replies
> and questions to the newsgroup so that others can learn
> from my ignorance and your wisdom.



> > Hi,

> > I have 20 autotext entries in a template. I have defined a listbox
> > (fmListStyleOption) in a userform and populated the listbox with the
> > autotext entries.

> > I need to know the best way to insert the selected autotext entries from
> the
> > listbox into the document. should I use bookmarks for each and every
> > autotext entry in the main document? Also providing me with a sample
code
> > for the "OK" button to insert each checked autotext entry from the
listbox
> > into the document will be highly appreciated.

> > Thanks in advance.

> > Raja



Tue, 29 Nov 2005 21:56:29 GMT  
 Insert Autotext Entries in a Document
Hi Jonathan,

One last question.

After some trials with the template, the listbox that contains the autotext
entries in the userform contains some items already checked instead of
having all the check boxes not checked!

Any ideas on what should be done to clean/initialize the listbox correctly?

Thanks in advance.

Raja


Quote:



> > Hi Jonathan,

> > Thanks a lot for your reply and Doug's.

> > I have inserted a bookmark called "Insert" in my template where the
> selected
> > autotext entries should go.  I don't care about the order or the
location
> > where the entries go as long as they all get inserted in a specific
place
> in
> > the document. I tried to complete the code to insert the text in the
> > document without succeeding. Consulting the VBA help only added to my
> > confusion.

> > You are kindly requested to give me the syntax of the "insert" method to
> use
> > to insert "strAutoTextName" entry into the document.

> Hi Raja

> Try this

> This code should be at the start of the routine somewhere outside the
loop,
> but after you have opened the target document

>    Dim myRange as Range
>    Set myRange = ActiveDocument.Bookmarks("Insert").Range

> This code goes in the loop

>    ActiveDocument.AttachedTemplate.AutoTextEntries(strAutoTextName).Insert
_
>        Where:=myRange, RichText:=True
>    myRange.Collapse Direction:=wdCollapseEnd

> --
> Regards
> Jonathan West - Word MVP
> MultiLinker - Automated generation of hyperlinks in Word
> Conversion to PDF & HTML
> http://www.multilinker.com
> Word FAQs at http://www.multilinker.com/wordfaq
> Please post any follow-up in the newsgroup. I do not reply to Word
questions
> by email



Tue, 29 Nov 2005 22:57:56 GMT  
 Insert Autotext Entries in a Document
Hi Raja,

The Selected property is read/write, so you can unset the selection of any
item in code. For instance, the following code would unselect everything in
the listbox

For i = 0 to ListBox1.ListCount - 1
    ListBox1.Selected(i) = False
Next i

--
Regards
Jonathan West - Word MVP
MultiLinker - Automated generation of hyperlinks in Word
Conversion to PDF & HTML
http://www.multilinker.com
Word FAQs at http://www.multilinker.com/wordfaq
Please post any follow-up in the newsgroup. I do not reply to Word questions
by email



Quote:
> Hi Jonathan,

> One last question.

> After some trials with the template, the listbox that contains the
autotext
> entries in the userform contains some items already checked instead of
> having all the check boxes not checked!

> Any ideas on what should be done to clean/initialize the listbox
correctly?

> Thanks in advance.

> Raja





> > > Hi Jonathan,

> > > Thanks a lot for your reply and Doug's.

> > > I have inserted a bookmark called "Insert" in my template where the
> > selected
> > > autotext entries should go.  I don't care about the order or the
> location
> > > where the entries go as long as they all get inserted in a specific
> place
> > in
> > > the document. I tried to complete the code to insert the text in the
> > > document without succeeding. Consulting the VBA help only added to my
> > > confusion.

> > > You are kindly requested to give me the syntax of the "insert" method
to
> > use
> > > to insert "strAutoTextName" entry into the document.

> > Hi Raja

> > Try this

> > This code should be at the start of the routine somewhere outside the
> loop,
> > but after you have opened the target document

> >    Dim myRange as Range
> >    Set myRange = ActiveDocument.Bookmarks("Insert").Range

> > This code goes in the loop

ActiveDocument.AttachedTemplate.AutoTextEntries(strAutoTextName).Insert

- Show quoted text -

Quote:
> _
> >        Where:=myRange, RichText:=True
> >    myRange.Collapse Direction:=wdCollapseEnd

> > --
> > Regards
> > Jonathan West - Word MVP
> > MultiLinker - Automated generation of hyperlinks in Word
> > Conversion to PDF & HTML
> > http://www.multilinker.com
> > Word FAQs at http://www.multilinker.com/wordfaq
> > Please post any follow-up in the newsgroup. I do not reply to Word
> questions
> > by email



Wed, 30 Nov 2005 03:57:18 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Macro that inserts Autotext loses styles of Autotext entry

2. Insert autotext entry in formfield

3. Help Inserting AutoText Entries

4. Problem with format on insert autotext, and in inserting elements with form fields

5. Change style of autotext entries

6. Help with code for checkboxes and autotext entries.

7. Autotext entries

8. Userform and Legal Autotext Entries

9. Delete ALL autotext entries?

10. Autotext entry exist

11. Automatically typing AutoText entries into a table

12. Tables from autotext entries?

 

 
Powered by phpBB® Forum Software