HelenT
02-10-2016, 04:33 AM
Hi,
I'm running the following code from a template. The template is attached to a document which I am opening by double clicking the document in a file explorer window, hence AutoOpen is invoked. The code appears to run (msg box 2 pops up) but when I navigate to the add-ins tab, the button is not there and when I type ?CommandBars("ChessSrch").Visible into the immediate window, it is set to false.
If I then set the Visible param from the Immediate window (CommandBars("ChessSrch").Visible = true), the button is displayed on the add-ins tab and operates correctly.
Can anyone please tell me what is happening? Why is the setting of .visible in the AutoOpen sub being ignored/reset by Word?
thanks, Helen.
Dim commandBar As commandBar
Dim firstButton As CommandBarButton
Sub AutoOpen()
' force show of chess search toolbar
On Error GoTo ErrHandler
Set commandBar = CommandBars("ChessSrch")
' If "ChessSrch" CommandBar already exists, display it:
commandBar.Visible = True
MsgBox ("Chess AutoOpen ran 1")
ErrHandler:
Set commandBar = CommandBars.Add("ChessSrch", 1, False, True)
Set firstButton = commandBar.Controls.Add(1)
firstButton.Style = Office.MsoButtonStyle.msoButtonCaption
firstButton.Caption = "chess searches"
firstButton.Tag = "chess_search"
firstButton.OnAction = "ChessSearch_Main"
commandBar.Visible = True
MsgBox ("Chess AutoOpen ran 2")
End Sub
I'm running the following code from a template. The template is attached to a document which I am opening by double clicking the document in a file explorer window, hence AutoOpen is invoked. The code appears to run (msg box 2 pops up) but when I navigate to the add-ins tab, the button is not there and when I type ?CommandBars("ChessSrch").Visible into the immediate window, it is set to false.
If I then set the Visible param from the Immediate window (CommandBars("ChessSrch").Visible = true), the button is displayed on the add-ins tab and operates correctly.
Can anyone please tell me what is happening? Why is the setting of .visible in the AutoOpen sub being ignored/reset by Word?
thanks, Helen.
Dim commandBar As commandBar
Dim firstButton As CommandBarButton
Sub AutoOpen()
' force show of chess search toolbar
On Error GoTo ErrHandler
Set commandBar = CommandBars("ChessSrch")
' If "ChessSrch" CommandBar already exists, display it:
commandBar.Visible = True
MsgBox ("Chess AutoOpen ran 1")
ErrHandler:
Set commandBar = CommandBars.Add("ChessSrch", 1, False, True)
Set firstButton = commandBar.Controls.Add(1)
firstButton.Style = Office.MsoButtonStyle.msoButtonCaption
firstButton.Caption = "chess searches"
firstButton.Tag = "chess_search"
firstButton.OnAction = "ChessSearch_Main"
commandBar.Visible = True
MsgBox ("Chess AutoOpen ran 2")
End Sub