Temporary CommandBars

The Temporary parameter of the CommandBars.Add method and the CommandBarControls.Add method does not apply to Word.
The Temporary feature is intended for other applications that do not support session-specific settings.
Because Word can store information in global templates or local templates, you can get all of the Temporary functionality without actually using the Temporary flag.

Dim commandsBarName As Office.CommandBar 
Set commandsBarName = CommandBars.Add(Name:=sBarName, _
                                      Position:=MsoBarPosition.msoBarFloating, _
                                      MenuBar:=False, _
                                      Temporary:=False)

If you're going to add CommandBar or CommandBarControl objects to Word at run-time, and you want them to be truly temporary, set the Application.CustomizationContext to something other than Normal.dot before you begin making your changes.
You should actually set this to point to your actual template instead.
Make sure you do not set the Temporary to True.

Dim OldContext As Object 
Set OldContext = Application.CustomizationContext

Application.CustomizationContext = ThisDocument

Call CmdBar_Create

Application.CustomizationContext = OldContext
ThisDocument.Saved = True

CustomizationContext Property

Returns or sets a Template or Document object that represents the template or document in which changes to menu bars, toolbars, and key bindings are stored.
Use the CustomizationContext property to set the template or document context prior to accessing the CommandBars collection.
Corresponds to the value of the Save in box on the Commands tab in the Customize dialog box (Tools menu).

CustomizationContext = NormalTemplate
 
CustomizationContext = ActiveDocument.AttachedTemplate

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrev