This is my button
Dim pan1button1 As New RibbonButton() pan1button1.Text = "STORE" pan1button1.ShowText = True pan1button1.ShowImage = True pan1button1.Image = Images.getBitmap(My.Resources.Store) pan1button1.LargeImage = Images.getBitmap(My.Resources.Store_L) pan1button1.Orientation = System.Windows.Controls.Orientation.Vertical pan1button1.Size = RibbonItemSize.Large pan1button1.CommandHandler = New RibbonCommandHandler
I have had a look online but i can seem to find how i assign the macro to the button
The macro i want to use it
"^C^C_StoreTree "
Thanks in advance
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
Basically, you specify the CommandHandler and CommandParameter properties of a ribbon item (button, in your case):
pan1button1.CommandHandler= New MyRibbonCommandHandler()
pan1button1.CommandParameter="^C^C_StoreTree "
Then you implement ICommand interface
Public class MyRibbonCommandHandler
Implement System.Windows.Input.ICommand
Public Function CanExecute(...)
....
End Function
Public Event ....
Public Sub Execute(parameter As Object) Implement....
Dim doc As Document=Application.DocumentManager.MdiActiveDocument
Dim riboonItem As RiboonCommandItem=TryCast(parameter, RibbonCommandItem)
If ribbonItem IsNot Nothing Then
doc.SendStringToExecute(ribbonItem.CommandParameter, True, False, True)
End If
End Sub
End class
Note the code here is just right off my head and entered through Visual Studio, not compiled, thus could have sytex error. Just meant to give you an idea how to do it.
Norman Yuan
Thanks
I have just managed to get it sorted just before i got your message
I am using The button's ID to run the macro
(i have since added the ID to it )
and then is what i had further down
Public Class RibbonCommandHandler Implements System.Windows.Input.ICommand Public Function CanExecute(ByVal parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute Return True End Function Public Event CanExecuteChanged(ByVal sender As Object, ByVal e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged Public Sub Execute(ByVal parameter As Object) Implements System.Windows.Input.ICommand.Execute Dim doc As Document = Application.DocumentManager.MdiActiveDocument If TypeOf parameter Is RibbonButton Then Dim button As RibbonButton = TryCast(parameter, RibbonButton) doc.SendStringToExecute(button.Id & " ", True, False, False) End If End Sub End Class
I have just changed this line so that it looks form the button ID and then executes it
doc.SendStringToExecute(button.Id & " ", True, False, False)
Can't find what you're looking for? Ask the community or share your knowledge.