Save Autotext entry to User.dot

S

Sammy

Hello,

I'm trying to create a macro that forces autotext entries to be saved in a
special template called User.dot instead of Normal.dot. I have the macro
tied to Alt+F3, this is how the users will save their autotext. Here's what
I have so far, the message boxes work but it still won't save the autotext
entry in the User.dot:

Sub UserAutoText()

Dim SelectText As Range
Dim AutoTextEntry As AutoTextEntry
Dim myTemplate As Template


Application.ScreenUpdating = False
On Error GoTo Quit
Set SelectText = Selection.Range
If SelectText = "" Then
MsgBox ("You Must Select Text First"), vbOKOnly + vbCritical, "Save
AutoText Entry"
Else: GoTo CreateAutoText
End If
GoTo Quit
CreateAutoText:
AutoTextEntry = InputBox("Word will save an AutoText entry from the current
selection in your User.dot. Please name your AutoText entry and then press
Enter.", Title:="AutoText Entry")
If AutoTextEntry = "" Then GoTo Quit
Dialogs(wdDialogFileOpen).Show

Documents.Open FileName:="C:\Program Files\Microsoft
Office\Office10\Startup\User.dot"
Set myTemplate = ActiveDocument.AttachedTemplate
myTemplate.AutoTextEntries.Add Name:=AutoTextEntry, _
Range:=SelectText
ActiveDocument.Save
ActiveDocument.Close
Quit:
Application.ScreenUpdating = True
End Sub

ANY IDEAS? THANK YOU FOR YOUR ASSISTANCE AND HAPPY HOLIDAYS.
 
J

Jay Freedman

There's similar code in the AutoTextLoader2.dot template that you can
download from http://jay-freedman.info, and you're welcome to use or adapt
any part of that.

The main difference seems to be that you're opening User.dot and then using
it as its own AttachedTemplate. The AutoTextLoader macro instead opens a
regular document _based on_ the template and then uses its AttachedTemplate
to store the entries.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

Sammy

THANKS JAY I WILL GIVE THIS A TRY.

Jay Freedman said:
There's similar code in the AutoTextLoader2.dot template that you can
download from http://jay-freedman.info, and you're welcome to use or adapt
any part of that.

The main difference seems to be that you're opening User.dot and then using
it as its own AttachedTemplate. The AutoTextLoader macro instead opens a
regular document _based on_ the template and then uses its AttachedTemplate
to store the entries.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

Sammy

I'm not sure how I can use this on the fly without a table. I need this to
work whenever a user creates an autotext entry. So with the User.dot
template loaded, anytime a user presses Alt+F3 and gives a name for the
selected text, the new entry gets saved in the User.dot. Can your macro be
used to accomplish this? Thanks again
 
J

Jay Freedman

The AutoTextLoader macro cannot be "used to accomplish this". You can pick
out the pieces that apply to your circumstances -- specifically, the parts
about getting access to the desired template and saving the entry in it --
and throw away the rest.

In your case, the AutoTextEntries.Add command uses Range:=SelectText to
specify what to save in the entry. That's all you need, so you can ignore
the "table" part of AutoTextLoader.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
S

Sammy

Okay thanks, I will give it a try.

Jay Freedman said:
The AutoTextLoader macro cannot be "used to accomplish this". You can pick
out the pieces that apply to your circumstances -- specifically, the parts
about getting access to the desired template and saving the entry in it --
and throw away the rest.

In your case, the AutoTextEntries.Add command uses Range:=SelectText to
specify what to save in the entry. That's all you need, so you can ignore
the "table" part of AutoTextLoader.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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