M
mikeFin
Hello !
I need some help. I have googled quiet a much, but couldn't find a solution
to my problem.
I have a piece of VBA-code, that creates a Toolbar.
It DOES work flawlessly when it is in a module of the Document!
But this same code does NOT work, when I place it in the module of a stencil
(of course at this time the code wasn't in the module of the document
anymore).
Here my code:
- - -
Sub CB_test()
Dim myCBs As CommandBars
Dim myCB As CommandBar
Dim myCBbtn As CommandBarButton
Set myCBs = Application.CommandBars
myCBs("myToolb1").Delete
Set myCB = myCBs.Add("myToolb1", msoBarTop, False, False)
myCB.Visible = True
Set myCBbtn = myCB.Controls.Add(msoControlButton, 793)
With myCBbtn
.DescriptionText = "Name1"
.TooltipText = "Name1"
.Caption = "Name1"
.OnAction = "myProc1"
.Style = msoButtonIconAndCaption
.state = msoButtonUp
End With
End Sub
Sub myProc1()
MsgBox "Buttons works!"
End Sub
- - -
The errors that came up are for the lines with ".OnAction" and ".state".
Here the errors respectively
Firt error:
"Run-time error ...
Method 'OnAction' of object '_CommandBarButton' failed"
Second error:
"Run-time error ...
Method 'State' of object '_CommandBarButton' failed"
Why does this work in the Document-Module, but not in the Stencil-Module?
Thanks in advance!!
I need some help. I have googled quiet a much, but couldn't find a solution
to my problem.
I have a piece of VBA-code, that creates a Toolbar.
It DOES work flawlessly when it is in a module of the Document!
But this same code does NOT work, when I place it in the module of a stencil
(of course at this time the code wasn't in the module of the document
anymore).
Here my code:
- - -
Sub CB_test()
Dim myCBs As CommandBars
Dim myCB As CommandBar
Dim myCBbtn As CommandBarButton
Set myCBs = Application.CommandBars
myCBs("myToolb1").Delete
Set myCB = myCBs.Add("myToolb1", msoBarTop, False, False)
myCB.Visible = True
Set myCBbtn = myCB.Controls.Add(msoControlButton, 793)
With myCBbtn
.DescriptionText = "Name1"
.TooltipText = "Name1"
.Caption = "Name1"
.OnAction = "myProc1"
.Style = msoButtonIconAndCaption
.state = msoButtonUp
End With
End Sub
Sub myProc1()
MsgBox "Buttons works!"
End Sub
- - -
The errors that came up are for the lines with ".OnAction" and ".state".
Here the errors respectively
Firt error:
"Run-time error ...
Method 'OnAction' of object '_CommandBarButton' failed"
Second error:
"Run-time error ...
Method 'State' of object '_CommandBarButton' failed"
Why does this work in the Document-Module, but not in the Stencil-Module?
Thanks in advance!!