custom menu on the menu bar

A

Anne Schouten

For many users I made with vba a custom menu option on the menu bar.
I placed an autoexec procedure in a Word template in the Startup folder.
So far everything goes alright.
However I would like to remove the menu when Word is closed.
An Autoexec or Workbook_Close procedure doesn't work.

Who can help me?

Anne
 
K

kozaw

For many users I made with vba a custom menu option on the menu bar.
I placed an autoexec procedure in a Word template in the Startup folder.
So far everything goes alright.
However I would like to remove the menu when Word is closed.
An Autoexec or Workbook_Close procedure doesn't work.

Who can help me?

Anne

Hi, Anne!

There are two way you can do.

1st Way.
delete the menu bar with Autoclose macro.
Autoclose macro will execute when you close activedocument.

Sub Autoclose()
Dim oBar As CommandBar
For Each oBar In CommandBars
If oBar.BuiltIn = False Then

oBar.Delete ' delete all custom bar OR use If oBar.Name =
"your bar name" Then oBar.Delete and exit for to avoid looping..

End If
Next oBar
Set oBar = Nothing
End Sub

2nd Way.
Setting Your menu bar as temporary. When your created your menu bar
with vb, please set it as temporary, then it will delete automatically
when you exit word.

Sub CreateMyCustomBar()
Dim oBar As CommandBar
Dim oButton As CommandBarButton

' delete your bar first.
For Each oBar In CommandBars
If oBar.Name = "your bar name" Then
oBar.Delete
Exit For
End If
Next oBar

Set oBar = CommandBars.Add("your bar name", , , True) ' set the
Temporary = True

' Do something here like adding buttons...

With oBar
.Visible = True
End With

Set oBar = Nothing
End Sub

Hope this may help. I prefer 2nd Way.
You can also done with setting customizationcontext

Ko Zaw
 
J

Jean-Guy Marcil

Anne Schouten was telling us:
Anne Schouten nous racontait que :
For many users I made with vba a custom menu option on the menu bar.
I placed an autoexec procedure in a Word template in the Startup
folder. So far everything goes alright.

Just curious here...
If the toolbar is created every time Word starts (as it will if you have
code that does that in an AutoExec sub in a global template located in the
Start-up folder), why would you want to delete it when closing Word? (It
will be recreated anyway next time Word starts...)
However I would like to remove the menu when Word is closed.
An Autoexec or Workbook_Close procedure doesn't work.

Who can help me?

Anne



--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

Anne Schouten

Hi Ko,

Thankyou very much for your answer.

The autoclose macro isn't called in my case as a template in the sartup
folder isn't opened as a file.

Your second option works fine with a new menubar, but unfortunately not with
a new control on the standard-menubar. Could it be that the Normal.dot is
closed before the template in the Startup folder, so the new menu is saved
in the Normal.dot?

Perhaps Jean-Guy is right I shouldn't bother about removing this menu. I
liked te remove the menu, just incase we decide to do without it in future.
But in that case I could distribute a template to remove the button from
each computer.

Anne
 

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