Inserting AutoText

G

Greg

I just noticed a problem inserting AutoText with VBA. Several weeks
ago I created several AutoText entries under a Style named "Toggles."
This resulted in a category in my AutoText list where I can select from
a variety of similiar entries. Today I recorded the following macro:

Sub InsertAutoText()
' Macro recorded 12/08/2005 by CDR G. K. Maxey
Application.DisplayAutoCompleteTips = True
NormalTemplate.AutoTextEntries("Checked Box").Insert Where:=Selection.
_
Range
End Sub

The action of recording the macro did in fact insert the AutoText entry
I have for a checked box.

I then attempted to run the macro and recieved a runtime error 5941
"The member of the collection does not exist."

Next I tried changing ("Checked Box") to (8). The "Checked Box" entry
is the 8th member of my AutoText enties in the list
Insert>AutoText>AutoText. The result after running this revised macro
is that "Confidential" is inserted in at the selection. Confidential
is the 10th entry in my AutoText list. :-(

Next I selected my checked box and created a new AutoText entry named
"Checked Box1" and changed the code in the above macro to "Checked
Box1." It performed as expected and inserted the checked box at the
selection.

I the problem is related to the fact that "Checked Box" is an AutoText
entry that I created in a style named "Toggles." How do you
programatically insert an AutoText entry created in this manner?

Thanks.
 
G

Greg

I just realized that "Checked Box" is actually located in an Addin. So
I tried:

Sub Test3()
Dim myTemplate As Template
Set myTemplate = "C:\Check Boxes and Buttons.dot"
myTemplate.AutoTextEntries("Checked Box").Insert Where:=Selection.Range
End Sub

I now get a type mismatch on the Set myTemplate line.

The new question is, how do I insert a AutoText entry that is located
in an Addin Template?
 
W

Word Heretic

G'day "Greg" <[email protected]>,

Look the names of the autotext entries and locate its true name.

Steve Hudson - Word Heretic

steve from wordheretic.com (Email replies require payment)
Without prejudice


Greg reckoned:
 
J

Jay Freedman

Greg said:
I just realized that "Checked Box" is actually located in an Addin.
So I tried:

Sub Test3()
Dim myTemplate As Template
Set myTemplate = "C:\Check Boxes and Buttons.dot"
myTemplate.AutoTextEntries("Checked Box").Insert
Where:=Selection.Range End Sub

I now get a type mismatch on the Set myTemplate line.

The new question is, how do I insert a AutoText entry that is located
in an Addin Template?

Hi Greg,

To get the Set myTemplate statement to work, you have to do this:

Set myTemplate = Application.Templates("C:\Check Boxes and Buttons.dot")

The path in the quotes must be the full path to the template, so if it's an
add-in because it's in the Startup folder, the code looks like

Dim myTemplate As Template
Dim StartupPath As String

StartupPath = Options.DefaultFilePath(wdStartupPath) & "\"
Set myTemplate = Application.Templates(StartupPath & _
"Check Boxes and Buttons.dot")
 
G

Greg

Steve,

I had the name right, but the wrong template. Here is the code I
needed to use.

Sub Test4()
Dim myTemp As Template
Set myTemp = Templates("C:\Check Boxes and Buttons.dot")
myTemp.AutoTextEntries("Checked Box").Insert Where:=Selection.Range
End Sub

It is interesting to note that the recorder is recording code that will
not work. It doesn't recognize that the AutoText Entry is not located
in the NormalTemplate.

Thanks.
 
C

Charles Kenyon

There are a number of ways to create and use clickable checkboxes in
documents / templates. Some require protected or locked forms, others do
not. Take a look at the Checkbox template available at
http://www.addbalance.com/word/download.htm#CheckboxAddIn for an exploration
of these. This is set up so it can be used as an Add-In.

--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


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

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