PDA

View Full Version : Solved: How to delete from menu my own item menu?



akokin
09-17-2008, 05:06 AM
Hello.
There is my own template (not Normal.dot) with macros (3). They has names: AutoExec, AutoExit and MyMacro. I created it as example. I used these macros from article http://www.bettersolutions.com/word/WCA723/NI825618332.htm
I saved my template to "Startup" folder.
Next I start Word and my macros was runs is good. Next I exit from Word (closed it) and deleted my template from "Startup" folder.
Next I again started Word and saw that my item menu don't removed from menu. Why? Maybe it is gotcha of Word? Or not? Why don't work macro AutoExit so it should?
Thank you very much.

I use Word 2003.

shamsam1
09-17-2008, 05:24 AM
hi
jut run this macro

Sub DeleteMenu()

On Error Resume Next

Application.CommandBars("Tools").Controls(msoControlButton).Delete
On Error GoTo 0

End Sub

akokin
09-17-2008, 06:31 AM
Thank you. I used some code which find and delete my item menu. But I wish to know how do it do using AutoExit. I need in it for my own add-ins for Word.
If user will wish to delete my add-ins then how to be? Explaine for every user or give they other macro? I think that it is not correct.

shamsam1
09-17-2008, 06:37 AM
in close event of word form add this
it will delete ur menutool when u close

Private Sub Document_Close()
On Error Resume Next

Application.CommandBars("Tools").Controls(msoControlButton).Delete
On Error GoTo 0
End Sub

lucas
09-17-2008, 08:56 AM
Why are you creating menu's on the fly in word?

check this out (http://slucas.virtualave.net/Wink/CustomMenuItem.htm)

The above will work in templates as well.

akokin
09-17-2008, 09:31 AM
Thank you for media lesson, but I asked only about VBA methods.

Shamsam1, sorry, but It not works.

lucas
09-17-2008, 09:48 AM
Thank you for media lesson, but I asked only about VBA methods.

So you are not open to an alternative even if it is better?

You are using old methods that are obsolete as Shamsam1 pointed out you should be using document close event instead of AutoExit even if you want to do it with vba.

vba is not the only solution to a problem and it can cause you more problems than it solves in some circumstances as you are finding out.

If you are just learning how to do it that is one thing but if you are trying to create a document for actual use I would rethink my method if I were you.

The method I reccommended is very stable and easy to configure or change.

If you want help with doing this with vba then post your document and we will go through it with you and show you how to make it work using vba.

hit post reply on the lower left of the last post and then scroll down till you find the button that says manage attachments.

TonyJollans
09-17-2008, 01:05 PM
This won't work if you are adding the menu customisation to the normal template.

I do agree with Steve (lucas), however, that you could include the customization in the AddIn instead of adding it every time you open and deleting it every time you close.

fumei
09-17-2008, 01:16 PM
And I will third that opinion. It should be in the Add-in. There is no need (nor is it efficient to do so) to add and delete over and over again.

akokin
09-18-2008, 12:21 AM
Dear collegues. You are right, but I should explain that I want. I want to set one item menu to user's menu. By clicking on this item it will run some macro and action. If user some time will wish to delete my macro then I want that it was becomes very simple. Therefore I wanted to use into my template of macros AutoExec and AutoExit. But I see that macro AutExec anyhow influences on global template Normal.dot.
Thereby I think that I should use the others methods but with VBA. All that user should do - to place my template into folder Startup.
Question: What can I do it somehow? I copied my example (myTemplate.dot) to there: http://www.box.net/shared/uehi17p77y
Thank you very much for any tips and help.
Sincerely, Anton Kokin.
P.S. I added my file as attachment.

TonyJollans
09-18-2008, 04:55 AM
I don't quite understand exactly what you want, but you can use the technique you have chosen. You must just make sure - what is good behaviour anyway - that the CustomizationContext is set to yout Template instead of Normal.

akokin
09-18-2008, 06:37 AM
I little stupid today, sorry. Of course, If I use my template then I can simply manually add my items to menu. And user will see they at once after set my template.
Sorry for my stupidity.