0

No matter what, I can't figure out how to add a button via UDF.
Tried to call it through a another Function/Sub, doesn't matter as long as initial caller is a Function.
Any ideas how to solve it? Any suggestion would be greatly appreciated.

Sub AddButtonAt(r As Range)
    With ActiveSheet.Buttons.Add(r.Left, r.Top, r.Width, r.Height)
        .Name = "Btn" & r.Address
        .caption = "B: " & r.Address
    End With
End Sub
Function addB()
    Call AddButtonAt(Selection)
End Function

Function addB() is just a helper. Ideally I'd use Function AddButtonAt(), if that would be possible.

Machine
  • 31
  • 4
  • If I understand, you want a function called by a cell (UDF) to add a button to the selected cell in a sheet? – Ricardo Diaz Feb 04 '21 at 20:50
  • Functions called from the sheet are not allowed to change things on the sheet. There are [WORKAROUNDS](https://stackoverflow.com/questions/23433096/using-a-udf-in-excel-to-update-the-worksheet) for true format items. I am not sure they will work for adding a button, in fact I am pretty sure it will not. – Scott Craner Feb 04 '21 at 21:13
  • @ScottCraner It looks like there's a hope, but it won't be easy. I'll experiment a bit with 'Parent.Evaluate ' or using Task. Thanks for help! – Machine Feb 04 '21 at 21:52

0 Answers0