View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Jake Marx[_3_] Jake Marx[_3_] is offline
external usenet poster
 
Posts: 860
Default OnAction command failure

Hi Peter,

As Tom noted, passing arguments via the OnAction property is not fully
supported. Instead of using a parameter in your Subroutine, you can use the
Parameter property of the CommandBarButton. You can get this property from
within the DataFiltera subroutine with:

Application.CommandBars.ActionControl.Parameter

But in order to do this, you'll have to switch to using CommandBars instead
of Menus. Here's (what should be) a working example:

Sub DropDownMenu5()
Dim nHelp As Integer

nHelp = Application.CommandBars(1).Controls("Help").Index
With Application.CommandBars(1).Controls.Add( _
Type:=msoControlPopup, befo=nHelp, temporary:=True)
.Caption = "ID Filter"
With .Controls.Add(Type:=msoControlButton, _
temporary:=True)
.Caption = "1"
.OnAction = "DataFiltera"
.Parameter = "1"
End With
With .Controls.Add(Type:=msoControlButton, _
temporary:=True)
.Caption = "2"
.OnAction = "DataFiltera"
.Parameter = "2"
End With
End With
End Sub

Sub DataFiltera()
Dim Kriteria As Integer

Kriteria = CInt(Application.CommandBars.ActionControl.Paramet er)

Select Case Kriteria
Case 1
Sheets("Sheet1").Range("A2") = "value 1"
Case 2
Sheets("Sheet1").Range("A2") = "value 2"
End Select
End Sub

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


wrote:
I use Excel 2000. My problem is that the following code
works only on my computer. I have tested the same code
on five different Excel 2000 computers but it works only
for me. The Toolsoptions, ToolsVBA project properties,
toolsdigital signature and toolsreferences
settings are the same for all (five) computers.
Any help is most appreciated.

Sub DropDownMenu5()
Set NewMenu = MenuBars(xlWorksheet).Menus.Add
(Caption:="ID Filter", Befo="Help")
Set MenuItemAdded = MenuBars(xlWorksheet).Menus("ID
Filter").MenuItems.Add(Caption:="1",
OnAction:="'DataFiltera 1'")
Set MenuItemAdded = MenuBars(xlWorksheet).Menus("ID
Filter").MenuItems.Add(Caption:="2",
OnAction:="'DataFiltera 2'")
End Sub

Sub DataFiltera(Kriteria As Integer)
Select Case Kriteria
Case 1
Sheets("Sheet1").Range("A2") = "value 1"
Case 2
Sheets("Sheet1").Range("A2") = "value 2"
End Select
End Sub