I would like to create the form control button by macro, as discussed here:
Insert form control button via VBA
Adding command buttons to worksheet at run time and also define events
and explained here:
Unfortunately, suddenly I got an error: Expected fonctuon or variable" with debugger pointing roughly the Selection
statement.
Sub SunButton()
'
' Macro1 Macro
'
'
ActiveSheet.Buttons.Add(964.2, 119.4, 139.2, 49.8).Select
Selection.OnAction = "Sun"
Selection.Characters.Text = "Sun"
With Selection.Characters(Start:=1, Length:=3).Font
.Name = "Calibri"
.FontStyle = "Bold"
.Size = 16
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 32
.Placement = xlFreeFloating
.PrintObject = False
End With
End Sub
I don't know what can be wrong here.
According to this thread:
https://www.mrexcel.com/board/threads/compile-error-expected-function-or-variable.308885/
it occurs, when you have another macro called "selection" but I don't have it in my case.
How can I remove this error and proceed my recorded macro?