CommandBarButton works in Document-Module but not in the Stencil-M

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!!
 
M

mikeFin

Hello again!

The most related topic with a detailed answer that I could find on google is:

http://www.dbforums.com/showthread.php?t=1205997

Unlinke in Excel, I finally found the "Disabled components" List under:

Help -> Privacy Options -> Add-ins

but I had no disabled Items, so I doesn't seem to be the solution to my
problem. I guess these disabled items are only for coders that use VB, but I
am using VBA right now.

Anyone an idea?
I do so much need this right now...
 
J

JuneTheSecond

mikeFin,

..OnAction = "myProc1"
is looking for the macro on the drawing.
First, please make sure the project name
of the stencil, for example "prjstn",
then
..OnAction = "prjstn!mdlname.myProc1"
might runs macro on the mdlname moduke of
the stencil prjstn project.

--
Best regards,
JuneTheSecond

Now, visual calculation is more visual.
http://www.geocities.jp/visualcalculation/english/index.html
 
M

mikeFin

Hello June!

a big THANK YOU!!
I tought this syntax with an exclamation point/mark was only for the
ShapeSheet.
When I Call a function without building a commandbar this wasn't needed, so
didn't think this would be the problem.

I am so thankful!!
Let me know if you have Paypal and I can make you a little donation. I don't
know if this is appropriate in a discussion-group on microsofts site, but you
guys here a so much helping out when there is a problem.

Thanks!
 

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