Reputation: 43
I have found how to create a button and I want to make it so when I press it it does the following function.
<-Button->
Sub AddButton()
Dim cb As CommandBar
Set cb = Application.CommandBars.Add("additional_toolbar", msoBarTop, , True)
With cb.Controls.Add(msoControlButton)
.Caption = "click me"
.OnAction = "macro_name"
.Style = msoButtonCaption
End With
cb.Visible = True
End Sub
<-Action that I want it to perform->
Sub CopySizeAndPosition()
' Usage: Select two shapes. The size and position of
' the first shape selected will be copied to the second.
Dim w As Double
Dim h As Double
Dim l As Double
Dim t As Double
With ActiveWindow.Selection.ShapeRange(1)
w = .Width
h = .Height
End With
With ActiveWindow.Selection.ShapeRange(2)
.Width = w
.Height = h
End With
End Sub
Do u know how I could do that?
Upvotes: 0
Views: 3320
Reputation: 14809
Change:
.OnAction = "macro_name"
To:
.OnAction = "CopySizeAndPosition"
Upvotes: 1