Autotext toolbar

D

D

I have a long list of autotext entries that I use, most of which are located under a "Plain Text" style, so when I'm working in a document that uses this "Plain Text" style, those are the only autotext entries that are shown. I frequently update these and add more. What I'm looking to do is write some code that will automatically create a scrollable toolbar (docked to the right side of Word) with all the autotext entries listed (needs to repopulate itself with all the latest available entries each time it's put into use). Perhaps a userform would have to be used, as I don't believe toolbars can be scrollable (?), they only give you that little pop up arrow when they run out of room. So, perhaps a way to populate a userform with links to all of these autotext entries, automatically, is all that is needed. The idea is to have the autotext entries always available to be used on the right hand side of the screen, so I don't have to use the slooow scroll that results when you scroll through autotext entries in the default autotext toolbar. Plus, if it were a typical scrollbar, it would stay in the last position, so I could easily click the same autotext entry again and again. A lot of the entries are similarly named, so I can't just type the start of the entry to display it (blasted 5 character recognition limit).

Thanks
 
C

Charles Kenyon

Uh, what's wrong with the built-in AutoText toolbar? If you just need the
menu, you can copy it to a custom toolbar and dock it where you like.
--

Charles Kenyon

See 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.

D said:
I have a long list of autotext entries that I use, most of which are
located under a "Plain Text" style, so when I'm working in a document that
uses this "Plain Text" style, those are the only autotext entries that are
shown. I frequently update these and add more. What I'm looking to do is
write some code that will automatically create a scrollable toolbar (docked
to the right side of Word) with all the autotext entries listed (needs to
repopulate itself with all the latest available entries each time it's put
into use). Perhaps a userform would have to be used, as I don't believe
toolbars can be scrollable (?), they only give you that little pop up arrow
when they run out of room. So, perhaps a way to populate a userform with
links to all of these autotext entries, automatically, is all that is
needed. The idea is to have the autotext entries always available to be
used on the right hand side of the screen, so I don't have to use the slooow
scroll that results when you scroll through autotext entries in the default
autotext toolbar. Plus, if it were a typical scrollbar, it would stay in
the last position, so I could easily click the same autotext entry again and
again. A lot of the entries are similarly named, so I can't just type the
start of the entry to display it (blasted 5 character recognition limit).
 
D

D

The problem is having to scroll through all the entries. I want all the entries listed, line by line, without having to use the default autotext toolbar's style of scroll. So, basically, one button for each autotext entry, on a toolbar. It'd be quite easy to make such a thing, just make a bunch of shortcuts to macros, each macro set to insert that autotext entry. But, I want to come up with something that will automatically do this, so I don't have chage the toolbar and macros manually each time an autotext entry is added or deleted.
 
C

Charles Kenyon

You can put AutoText entries directly on a custom menu without the
intercession of a macro. If you don't want a menu to scroll through, you can
put custom buttons on the toolbar (also representing the AT entries
directly).

I haven't done this so don't have the code off-hand to automatically
populate such a toolbar or menu. However, I have some general thoughts/ideas
about generating such a custom toolbar each time your global template loads
(each time Word starts).

1) Put all of your AutoText that you want on the toolbar in a single global
template that also contains the toolbar.

2) The code to generate your toolbar would be in an AutoExec procedure in
the template.

3) Make sure that when your procedure runs that the customization context is
set to be your template and not the user's normal.dot. Failing to do this
will turn your global into something your users will regard as a virus.

4) When your procedure to populate the toolbar finishes, it should change
its saved status to "True." This is to keep your user from getting a prompt
about whether to save changes to your template when they quit Word.

I recommend against using such an automatic procedure unless you are daily
adding AutoText to your template. If you are daily adding AutoText to your
template, I advise against it anyway because before long your toolbar will
fill up your screen! (There's a reason Word accesses AutoText using a
scrolling list.) You will find that adding AutoText to a template other than
normal.dot requires a couple of steps. It is not that hard to add yet
another step of opening your template and modifying your custom toolbar
manually to add another button for the new AutoText entry.

How are you going to distinguish among the buttons for your AutoText entries
or do you want the user to hold the mouse over each button until the tooltip
tells the contents? That would be more painful than scrolling through a menu
for me. If you are automatically populating the toolbar with buttons, the
user will not be able to rely on the position of the button for a particular
AT entry to remain constant.
--

Charles Kenyon

See 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.

D said:
The problem is having to scroll through all the entries. I want all the
entries listed, line by line, without having to use the default autotext
toolbar's style of scroll. So, basically, one button for each autotext
entry, on a toolbar. It'd be quite easy to make such a thing, just make a
bunch of shortcuts to macros, each macro set to insert that autotext entry.
But, I want to come up with something that will automatically do this, so I
don't have chage the toolbar and macros manually each time an autotext entry
is added or deleted.
 
C

Charles Kenyon

All I know about autopopulation is that it can be done.

I've never used a listbox but it looks like it might work, especially
scrolling with a checkbox for each entry. I'm not sure it is an improvement
over the standard AutoText toolbar, but that is up to you.

The style an AutoText entry is saved in is only marginally related to the
style that will be used when it is inserted. If the entry has one or more
paragraph marks as part of the entry, those paragraph marks (and the related
formatting including styles) will be carried into your new document. The
style that is at the insertion point will not be changed by insertion of an
AutoText entry. Either the entry ends with a paragraph mark, in which case
the style at the insertion point will be the paragraph following your entry,
or the entry does not end with a paragraph mark, so the last paragraph of
the entry will be formatted using the style at the insertion point.

Obviously AutoText entries are organized in Word according to the style used
when they were saved. Again, that is the style for the last paragraph of
multi-paragraph entries.

I hope others can help you with the population question. You might want to
post a separate message on that with a subject of "populate listbox with
AutoText entry names."

Note that you will want to use the AutoTextEntries.Insert method to put them
into your document.
--

Charles Kenyon

See 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.

D said:
Okay, let me try and restate what I think would work best. A lot of the
points mentioned make sense. So, now I'm thinking the best way to do it
would be a userform. When a certain macro is run, this userform would be
displayed, and each autotext entry under the "Plain text" style would be
listed in a listbox on the userform. Each choice in the listbox (set to a
rather large size, about the height of the Word window.) would be one of the
autotext entrys. Using a Click event, each time one of the lines is
clicked, that autotext would be inserted. Basically, a way of having all
the autotext entries always displayed on the right hand side of the screen,
ready to be used until the userform is closed.
The main hang up is trying to autopopulate the list box with all the
autotext entries, each time the userform is displayed. And having each one
of these listed entries insert the appropriate autotext when clicked. It
seems like that would be rather easy, since the listed name of the autotext
in the listbox would be the entry's real name, and could be put into a
variable that would be used to insert an autotext with that variable's name.
It's just the autopopulate thing that has me hung up. Another problem might
be trying to list just the autotext entries under the "Plain text" style,
and getting them to use that style when inserting them. When I insert an
autotext from the normal autotext menu, it inserts with the appropriate
style. But if I insert the same autotext using a macro, it inherits the
style at the insertion point.
 
D

D

Thanks for all the hel

----- Charles Kenyon wrote: ----

All I know about autopopulation is that it can be done

I've never used a listbox but it looks like it might work, especiall
scrolling with a checkbox for each entry. I'm not sure it is an improvemen
over the standard AutoText toolbar, but that is up to you

The style an AutoText entry is saved in is only marginally related to th
style that will be used when it is inserted. If the entry has one or mor
paragraph marks as part of the entry, those paragraph marks (and the relate
formatting including styles) will be carried into your new document. Th
style that is at the insertion point will not be changed by insertion of a
AutoText entry. Either the entry ends with a paragraph mark, in which cas
the style at the insertion point will be the paragraph following your entry
or the entry does not end with a paragraph mark, so the last paragraph o
the entry will be formatted using the style at the insertion point

Obviously AutoText entries are organized in Word according to the style use
when they were saved. Again, that is the style for the last paragraph o
multi-paragraph entries

I hope others can help you with the population question. You might want t
post a separate message on that with a subject of "populate listbox wit
AutoText entry names.

Note that you will want to use the AutoTextEntries.Insert method to put the
into your document
--

Charles Kenyo

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

D said:
Okay, let me try and restate what I think would work best. A lot of th
points mentioned make sense. So, now I'm thinking the best way to do i
would be a userform. When a certain macro is run, this userform would b
displayed, and each autotext entry under the "Plain text" style would b
listed in a listbox on the userform. Each choice in the listbox (set to
rather large size, about the height of the Word window.) would be one of th
autotext entrys. Using a Click event, each time one of the lines i
clicked, that autotext would be inserted. Basically, a way of having al
the autotext entries always displayed on the right hand side of the screen
ready to be used until the userform is closedautotext entries, each time the userform is displayed. And having each on
of these listed entries insert the appropriate autotext when clicked. I
seems like that would be rather easy, since the listed name of the autotex
in the listbox would be the entry's real name, and could be put into
variable that would be used to insert an autotext with that variable's name
It's just the autopopulate thing that has me hung up. Another problem migh
be trying to list just the autotext entries under the "Plain text" style
and getting them to use that style when inserting them. When I insert a
autotext from the normal autotext menu, it inserts with the appropriat
style. But if I insert the same autotext using a macro, it inherits th
style at the insertion point
 
J

Jay Freedman

Hi D

I haven't worked all the bugs out of this yet, but you may want to play with
it and see if it's headed in the right direction.

In a template that you save as atform.dot, create a userform (I named it
frmATmgr) with a listbox (lbAutoText) and a Close button (cmdClose). Put the
following code in the userform:

------------------
Public ThisTemplate As Template

Private Sub cmdClose_Click()
Me.Hide
End Sub

Private Sub lbAutoText_Click()
Dim strATselected As String
Dim oRg As Range

strATselected = lbAutoText.List(lbAutoText.ListIndex)
Set oRg = Selection.Range
ThisTemplate.AutoTextEntries(strATselected).Insert _
Where:=oRg, RichText:=True
oRg.Style = "Plain Text"
End Sub

Private Sub UserForm_Activate()
Dim oAT As AutoTextEntry

For Each oAT In ThisTemplate.AutoTextEntries
If LCase(oAT.StyleName) = "plain text" Then
lbAutoText.AddItem oAT.Name
End If
Next oAT

If lbAutoText.ListCount = 0 Then
MsgBox "No 'Plain Text' entries found"
Me.Hide
End If

lbAutoText.ListIndex = 0
End Sub
------------------

Put this code in a regular module in the same template:

------------------
Public Sub ATmanager()
Dim dlg As frmATmgr
Dim bTemplateFound As Boolean
Dim tmpTemplate As Template

bTemplateFound = False
For Each tmpTemplate In Templates
If LCase(tmpTemplate.Name) = "atform.dot" Then
bTemplateFound = True
Exit For
End If
Next tmpTemplate

If Not bTemplateFound Then
MsgBox "Template not found", , "Error"
Exit Sub
End If

Set dlg = New frmATmgr
With dlg
Set .ThisTemplate = tmpTemplate
.Show vbModeless
End With

Set dlg = Nothing
End Sub
------------------

Assign a shortcut key or toolbar button to the ATmanager macro, and add all
your Plain Text AutoText entries to the same template.

Copy the atform.dot file into Word's Startup folder and restart Word.

One of the bugs I mentioned is that as soon as the userform comes up, the
first entry in the list will be inserted. I know why this happens (setting
..ListIndex = 0 in the Activate procedure causes the lbAutoText_Click event
to fire), I just didn't take the time to program around it.

You may also not be happy that inserting an AT causes the whole paragraph to
take on the Plain Text style -- that's a result of the line oRg.Style =
"Plain Text" -- but Plain Text is a paragraph style, so you either get it
for the whole paragraph or not. The way around this is, when you set up the
AutoText entries, apply a character style that has the same font formatting
as the Plain Text style. Then remove the oRg.Style line.
 
C

Charles Kenyon

Thanks for pitching in. I may play with this a bit myself. I had run out of
helpful things to say and wasn't sure anyone else was following the thread.
--

Charles Kenyon

See 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.
 
D

D

Thanks a lot for the help. It looks like it should be pretty helpful. I'll be able to try it out come Monday or so

----- Jay Freedman wrote: ----

Hi

I haven't worked all the bugs out of this yet, but you may want to play wit
it and see if it's headed in the right direction

In a template that you save as atform.dot, create a userform (I named i
frmATmgr) with a listbox (lbAutoText) and a Close button (cmdClose). Put th
following code in the userform

-----------------
Public ThisTemplate As Templat

Private Sub cmdClose_Click(
Me.Hid
End Su

Private Sub lbAutoText_Click(
Dim strATselected As Strin
Dim oRg As Rang

strATselected = lbAutoText.List(lbAutoText.ListIndex
Set oRg = Selection.Rang
ThisTemplate.AutoTextEntries(strATselected).Insert
Where:=oRg, RichText:=Tru
oRg.Style = "Plain Text
End Su

Private Sub UserForm_Activate(
Dim oAT As AutoTextEntr

For Each oAT In ThisTemplate.AutoTextEntrie
If LCase(oAT.StyleName) = "plain text" The
lbAutoText.AddItem oAT.Nam
End I
Next oA

If lbAutoText.ListCount = 0 The
MsgBox "No 'Plain Text' entries found
Me.Hid
End I

lbAutoText.ListIndex =
End Su
-----------------

Put this code in a regular module in the same template

-----------------
Public Sub ATmanager(
Dim dlg As frmATmg
Dim bTemplateFound As Boolea
Dim tmpTemplate As Templat

bTemplateFound = Fals
For Each tmpTemplate In Template
If LCase(tmpTemplate.Name) = "atform.dot" The
bTemplateFound = Tru
Exit Fo
End I
Next tmpTemplat

If Not bTemplateFound The
MsgBox "Template not found", , "Error
Exit Su
End I

Set dlg = New frmATmg
With dl
Set .ThisTemplate = tmpTemplat
.Show vbModeles
End Wit

Set dlg = Nothin
End Su
-----------------

Assign a shortcut key or toolbar button to the ATmanager macro, and add al
your Plain Text AutoText entries to the same template

Copy the atform.dot file into Word's Startup folder and restart Word

One of the bugs I mentioned is that as soon as the userform comes up, th
first entry in the list will be inserted. I know why this happens (settin
..ListIndex = 0 in the Activate procedure causes the lbAutoText_Click even
to fire), I just didn't take the time to program around it

You may also not be happy that inserting an AT causes the whole paragraph t
take on the Plain Text style -- that's a result of the line oRg.Style
"Plain Text" -- but Plain Text is a paragraph style, so you either get i
for the whole paragraph or not. The way around this is, when you set up th
AutoText entries, apply a character style that has the same font formattin
as the Plain Text style. Then remove the oRg.Style line

--
Regards
Jay Freedma
Microsoft Word MVP FAQ: http://word.mvps.or

Charles Kenyon wrote
 

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