PDA

View Full Version : Solved: Adding AutoText entry to custom toolbar menu



dchapin
06-18-2008, 08:26 AM
I have created a file named spswdt.dot and stored it in the Word startup directory so that it loads when word loads. The template contains a menubar. One of the menubar menus is built to hold auto text entries that the user creates.

I want to automate the process of storing the autotext entry in normal.dot and then adding the entry to the specific autotext menu that is a part of tmy spswdt.cot template.

The user selects the text they want to store then runs my macro (another object on custom menubar) that macro runs:

NormalTemplate.AutoTextEntries.Add Name:="AUTOTEXT_NAME", Range:= Selection.Range

this places the autotext into normal.dot.

Now I want to add this item to my menu...

CommandBars("Custom Popup 15").Controls.Add Type:=msoControlButton, ID :=2205, Before:=3, Parameter:="AUTOTEXT_NAME"

When run, I get a runtime error #9, subscript out of range....

Anyone know how this might be achieved?

Thanks in advance
Dan

fumei
06-18-2008, 09:51 AM
1. why not store the AutoText in spswdt.dot?

2. I used your code (but changed it to "Standard", as I do not have your "Custom Popup 15":

CommandBars("Standard").Controls.Add Type:=msoControlButton, _
ID:=2205, Before:=3, _
Parameter:="AUTOTEXT_NAME"

and did not get an error. Interestingly, it put:

"Apply AutoText Name" as a button. Also interestungly, it always puts that. If I run:

Sub yadda()
CommandBars("Standard").Controls.Add _
Type:=msoControlButton, ID:=2205, _
Before:=3, Parameter:="Yadda Blah Whatever"
End Sub

it still puts "Apply AutoText Name" as the button text. Which I did not know, so I have learned something.

I do not do this kind of thing, so I am not sure why this is the case.

Parameter is a string value for a control.

In your macro that runs:
NormalTemplate.AutoTextEntries.Add _
Name:="AUTOTEXT_NAME", Range:= Selection.Range

are you picking up a unique name for "AUTOTEXT_NAME"?

Also, I am not quite following what is going on. To insert an AutoText by code, you execute:
NormalTemplate.AutoTextEntries("HeaderA") _
.Insert Where:=Selection.Range, _
RichText:=True

which inserts the AutoText named "HeaderA" at the Selection point. It can, of course, actually be inserted anywhere. AutoText are inserted at a Range. It does NOT have to be the Selection.Range.
NormalTemplate.AutoTextEntries("HeaderA") _
.Insert Where:=ActiveDocument.Sections(2).Headers(1).Range, _
RichText:=True
would insert the AutoText "HeaderA" in the Primary header of Section 2.

I suspect that your subscript out of range may have something to do with ("Custom Popup 15").

MOS MASTER
06-18-2008, 12:18 PM
Hi, :hi:

Just an idea.
Creating controls by code is not always necessary.

In your custom template:
Why not create your menu's and buttons by hand as Steve shows in this video tutorial: http://slucas.virtualave.net/Wink/CustomMenuItem.htm

This way you only have to create macro's and drag them to the menu. (give names, icon, whatever by had)

And you done.

HTH

dchapin
06-18-2008, 02:45 PM
I am not storing the autotext in my .dot file because my menubar is loaded primarily with menus that hold sample coding text samples for the user. I want to programatically give them the ability to add thier own autotext entries into A SPECIFIC menu on the bar that will not "gum" up the dot file that I distribute. ie My .dot file will hold my autotext samples and thier normal.dot will hold their additional stored entries.

I would like to create a macro that will open a form where the user can "do" some things with the menu that I have created for their use. By "do" I mean create and name submenu and name and save new autotext entries.

It appears that when a template is placed in the startup directory, it "locks" the menubar from being edited. SOOOO I am thinking that what I want to do just is not possible. I simply want to control where "what menu" the user stores thier autotext entries in. I do understand how to do this by hand without programming a solution, but my users are "less knowledgeable" then me and I figured that creating a method to help them with the process of:

Select text,
ALT-F3,
Type a name
Click OK
on menu, click on Tools/Customize
Click on commands tab
scroll down and select autotext
find your new entry in the list
drag your entry up to toolbar and drop into toolbar
(just your menu, not mine)
Close customize menu

I was hoping to replace this with a proceedure of

select text
Click Add New Snippet(on my menu bar)
approve name (or edit)
press ok

Then have the entry appear in the menu that I have created for them automatically. I am open to any suggestions on ways to achieve this if possible, but I do realize that it may be impossible.

Any information, anyone can be add so I can complete this or scratch it off my list would be great.

Thanks
Dan

MOS MASTER
06-18-2008, 03:08 PM
Hi Dan, :yes

I'm not sure (I have to test first) if what you want is possible. But usualy a lot is possible.

But I have no idea how your .dot file looks like or how the result should look like.

So do me a favour and do the following:
1. Create a dot file with your default menu (Please include default empty macro's so I know what you want where)
2. Create a dot file with the end result you're looking for. (You can just drag a new menu on there and items. I'm interested in the look and feel)

If I have this I'll try and see what's possible.

dchapin
06-18-2008, 03:35 PM
Thanks MOS MASTER!

Here is a base doc template with the menu bar. I want to help the user to add autotext to the menu named ?My Code Snippets? by selecting it in the document and clicking a button ?not yet added? that will run the ?ddcInsert? macro. (the problem).

In a perfect world I would want to be able to, using a userform, provide the autotext-name field, to change or edit, and some ability to save the new autotext item into a sub-menu under the ?My Code Snippets? menu, via a combobox where they can select the sub-menu to save it in. As we as the ability to create a new submenu under ?My Code Snippets?

Thanks For your Time With This
Dan

dchapin
06-19-2008, 01:09 PM
To resolve this issue, I am using an AUTOTEXTLIST, which I store on my menubar. Simulated folders are created by creating a style, which I can automate. To show autotext entries pertaining to a specific group, I assign a style and then select that style programmitically after the user has selected the text.

Now all a user has to do when inserting (searching for) an autotext entry is change the style. The AUTOTEXTLIST updates on my menu to list those items associated with that style and all is well with the world.

This does not do everything I wanted but provides a rather nice solution to the base problem.

MOS MASTER
06-19-2008, 02:40 PM
Hi Dan, :hi:

Sounds like a good workarround. And you can always improve on it later if it doesn't work well enough.

Till next time...