问题
With this code, I have created multiple instances of button using copy and paste but when I change the caption of second button, it is changing the caption of first button
Sub CopyActiveX(address)
Application.ScreenUpdating = False
Dim X As OLEObject, Y As OLEObject
Dim newButtonName As String
Dim count As Integer
count = 0
For Each X In ActiveSheet.OLEObjects
count = count + 1
Debug.Print X.Name
If X.Name = "btnFindSeries" Then
newButtonName = X.Name + "" + CStr(count)
End If
Next X
Set X = Sheets("Sheet1").OLEObjects("btnFindSeries")
Set Y = X.Duplicate
Dim xName As String
xName = X.Name
Y.Cut
With Sheets("Sheet1")
.Paste Destination:=Worksheets("Sheet1").Range(address)
.OLEObjects(.OLEObjects.count).Name = newButtonName
.Activate
End With
AddSheetEventButMouseDown newButtonName
Application.ScreenUpdating = True
End Sub
Caption: Called using .OnAction = "SetCaption"
of type msoControlButton
from context menu
Public Sub SetCaption()
NavigatorType = CommandBars.ActionControl.Parameter
ActiveSheet.OLEObjects("btnFindSeries").Object.Caption = NavigatorType
End Sub
I know that the above code is updating only on button caption
but how do I dynamically get reference to second button and update caption when clicked on context menu?
来源:https://stackoverflow.com/questions/61843910/how-to-change-the-caption-of-multiple-button-instances-in-excel-vba