Autotext and Word VBA

B

Ben M

Hi,

I have previously created a template that has several checkboxes.
When selecting a checkbox, that triggers an autotext entry to be
inserted into the document. This works great!

However... I need to expand this further now, and this is where I face
a problem or two. In my new design, I need a different set of check
boxes to display, and this should be accomplished by selecting one of
two option buttons.

When (for example) option button one is selected, an autotext entry
should be inserted. This entry should display the appropriate set of
checkboxes. Obviously when checking a check box, an event should
occur (as it did previously).

The problem I face is the autotext entry with the checkboxes does not
function, as it's trying to reference code that does not exist in the
*document*. The code actually exists in the *template*.

How can I make the document look at the template for the code? It's
also interesting to note that as soon as I select one of the option
buttons and display the new autotext entry with checkboxes, all my
other contols no longer work. It seem that my link to the template is
severed in some way.

Hope you can help me :)

Thanks,
Ben (Frustrated)
 
C

Chuck

Assuming that you're working with macrobuttons to show checkboxes etc, the
underlying macros would need to be stored in an add in and that add in would
need to be loaded. Is the template that contains your macrobutton in your
Startup folder?
 
C

Claudia

I'm having a similar problem as the person originally posting. I've created a
global template that stores macros and AutoText entries for use by all users
in our office. I want the user to be able to run a macro that inserts the
AutoText but I'm getting a Run Time error because it's looking for AutoText
in the document when it the AutoText is actually stored in the global
template. The advantage to writing a macro to insert the AutoText is I can
insert Input Boxes into the inserted AutoText for boilerplate automation.
This, of course, works swell if I have the template open. But not when I
simply add the template as a global.

Like the person posting this question, I need to know how to get it to look
for AutoText in the *template*. The template is added using "Templates and
Add-Ins."

Claudia
 
C

Chuck

Try this, where "AutoText.dot" is the template where you've stored your
autotext entry and AUTOTEXT_PATH is where AutoText.dot is located:

Dim tmpTemplate As Template

Set tmpTemplate = Templates("C:\AUTOTEXT_PATH\AutoText.dot")

tmpTemplate.AutoTextEntries("YourAutoTextEntryName").Insert _
Where:=Selection.Range

Set tmpTemplate = Nothing
 
C

Chuck

PS -- your autotext template may still need to be loaded as a global
template. You can do that as follows, I do it in Normal.dot AutoExec macro
so it's available from the get go:

If Dir$("C:\AUTOTEXT_PATH\AutoText.Dot") <> "" Then
'load add in
AddIns.Add _
FileName:="C:\AUTOTEXT_PATH\AutoText.Dot", _
Install:=True
End If
 
C

Claudia

Chuck said:
PS -- your autotext template may still need to be loaded as a global template. <

So, it's not sufficient to have the global template loaded from Templates
and Add-Ins? Here's the macro as I've rewritten it. It's not working - still
getting a Run Time error. If you could tell me where I have it wrong, that
would be wonderful (this is run with the global template loaded).

Sub TestAutoTextInsert()
'
' TestAutoTextInsert Macro
' Macro recorded 3/9/2005 by Claudia Carvalho
'
Dim tmpTemplate As Template

Set tmpTemplate = Templates("V:\Forms_Word\OFFICE\Macros.dot")

tmpTemplate.AutoTextEntries("Intro Rogs Answer").Insert _
Where:=Selection.Range

Set tmpTemplate = Nothing

End Sub
 
C

Chuck

What specific run time error are you getting? "5941 - The requested member
of the collection does not exist"? Are you sure your autotext entry name is
spelled correctly? Are you sure the global template is actually loaded?

It should work whether you load the global template manually or through code.

Chuck
 

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