Hi and thanks for reading my post,
I've just spent half an afternoon looking thru advices on this and nothing works.
I have Word XP, I create a commandbar via VBA and then want to add a button that calls either a sub or a function with a parameter. That way I want to have a toolbar with several buttons that all call the same sub or function but each with a different parameter. Anything I try returns (when commandbar button clicked) "The macro cannot be found or has been disabled because of your Macro security settings."
Spomething is weird here, because calling a sub w/o a parameter works fine. Just for the record, my macro security is set to med, but i tested with low too with the same results.
I tested everything for example here: No results. Using the same code produces an error with me every time. I've read somewhere that this might be an MS error, that got later fixed, but I cannot be sure about it.
Many thanks advance for any kind help!!!
Best regards,
Pavel
My current code:
[tt]
Sub Test()
Dim xComBar As CommandBar
Set xComBar = Application.CommandBars.Add("testbar")
xComBar.Position = MsoBarPosition.msoBarTop
xComBar.Visible = True
Dim xComBarCntrl As CommandBarControl
Set xComBarCntrl = xComBar.Controls.Add(msoControlButton)
xComBarCntrl.Caption = "thebutton"
xComBarCntrl.Style = msoButtonCaption
xComBarCntrl.OnAction = "'Testit ""a"",""b""'"
End sub
Function testIt(x, y)
MsgBox x & ", " & y
End Function
[/tt]
I've just spent half an afternoon looking thru advices on this and nothing works.
I have Word XP, I create a commandbar via VBA and then want to add a button that calls either a sub or a function with a parameter. That way I want to have a toolbar with several buttons that all call the same sub or function but each with a different parameter. Anything I try returns (when commandbar button clicked) "The macro cannot be found or has been disabled because of your Macro security settings."
Spomething is weird here, because calling a sub w/o a parameter works fine. Just for the record, my macro security is set to med, but i tested with low too with the same results.
I tested everything for example here: No results. Using the same code produces an error with me every time. I've read somewhere that this might be an MS error, that got later fixed, but I cannot be sure about it.
Many thanks advance for any kind help!!!
Best regards,
Pavel
My current code:
[tt]
Sub Test()
Dim xComBar As CommandBar
Set xComBar = Application.CommandBars.Add("testbar")
xComBar.Position = MsoBarPosition.msoBarTop
xComBar.Visible = True
Dim xComBarCntrl As CommandBarControl
Set xComBarCntrl = xComBar.Controls.Add(msoControlButton)
xComBarCntrl.Caption = "thebutton"
xComBarCntrl.Style = msoButtonCaption
xComBarCntrl.OnAction = "'Testit ""a"",""b""'"
End sub
Function testIt(x, y)
MsgBox x & ", " & y
End Function
[/tt]