I have a loop in which I am adding ActiveX buttons in a particular sheet. But no matter how big loop is it is adding only one button. The loop is on rows of the sheet. Each time it should come to new row and add a button. But first time its coming to a row, adds the button and then function gets terminated. Even msgbox written after the line that adds the dynamic button does not executes. Below is the code:
Public Function AddButton(strSheetName, counter)
Dim btn As OLEObject
Dim cLeft, cTop, cWidth, cHeight
With Worksheets(strSheetName).Range("J" & (6 + counter))
cLeft = .Left
cTop = .Top
cWidth = .Width
cHeight = .Height
End With
With Worksheets(strSheetName)
btn = .OLEObjects.Add(ClassType:="Forms.Label.1", Link:=True, DisplayAsIcon:=False, Left:=cLeft, Top:=cTop, Width:=cWidth, Height:=cHeight)
End With
MsgBox "After Adding button"
End Function
Now This function is getting called in a loop. In first iteration it comes to the function adds a button to desired location and immediately after adding the button this function and the calling function(and hence the loop) gets terminated. Even the msgbox(After Adding Button) does not executes.
What may be the reason? Any help? Thanks in advance Akki J