I want to know if it is possible to create a macro "dynamically"? I am working on a project that will create buttons and add them to a "User's Toolbar". I then need each button to perform a similar but separate action. (the attached code should explain.)
The code that I need to generate, if possible is the following code:
The buttons can be generated with the following code.
Thanks
Oscar
The code that I need to generate, if possible is the following code:
Code:
' used with button to call sName and apply the style
Sub uName(sName)
Selection.Style = ActiveDocument.Styles(sName)
End Sub
The buttons can be generated with the following code.
Code:
sub uName (sName)
Dim myPop As CommandBarPopup
Dim myBut As CommandBarButton
Dim myToolbarName As String
myToolbarName = "User's Styles"
Set myPop = CommandBars(myToolbarName).Controls.Add(Type:=msoControlPopup)
myPop.Caption = sName
Set myBut = myPop.Controls.Add(Type:=msoControlButton)
myBut.Caption = sName
myBut.FaceId = 59 'smilly
myBut.OnAction = uName ' macro name
end sub
Thanks
Oscar