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