Home

Excel on MacOS using VBA to create a button

%3CLINGO-SUB%20id%3D%22lingo-sub-236423%22%20slang%3D%22en-US%22%3EExcel%20on%20MacOS%20using%20VBA%20to%20create%20a%20button%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-236423%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EI%20have%20a%20spreadsheet%20that%20uses%20a%20button%20to%20create%20another%20button.%20It%20has%20worked%20for%20the%20past%20couple%20of%20years%20up%20until%20recently%20when%20a%20couple%20of%20systems%20were%20updated%20to%20Excel%2016.16.1%20(MacOS).%20This%20issue%20only%20started%20occurring%20on%20Excel%20for%20Mac.%20Something%20with%20the%20latest%20revision%20is%20breaking%20the%20VBA%20control%20that%20allows%20this%20to%20function.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EHere's%20the%20code%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3ESub%20new_button()%3CBR%20%2F%3E'Click%20this%20button%20to%20make%20more%20buttons%3CBR%20%2F%3E'Numb%20is%20an%20index%20that%20increases%20everytime%20the%20button%20is%20pressed%3CBR%20%2F%3EDim%20numb%20As%20Integer%3CBR%20%2F%3Enumb%20%3D%20Worksheets(%22Sheet1%22).Range(%22F2%22).Value%3CBR%20%2F%3EDim%20r%20As%20Range%3CBR%20%2F%3E'These%20are%20the%20strings%20that%20exist%20on%20the%20spreadsheet%3CBR%20%2F%3EDim%20verline%20As%20String%3CBR%20%2F%3Everline%20%3D%20%22New%20Button%20Goes%20Here%20%22%20%26amp%3B%20numb%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20Each%20r%20In%20Range(%22D10%3AD29%22)%3CBR%20%2F%3E'This%20will%20search%20for%20the%20string%20then%20add%20the%20%22New%20Button%22%20button%3CBR%20%2F%3EIf%20r.Value%20Like%20verline%20Then%3CBR%20%2F%3EWith%20r.Parent.Buttons.Add(r.Left%2C%20r.Top%2C%20r.Width%2C%20r.Height)%3CBR%20%2F%3E.Font.Bold%20%3D%20True%3CBR%20%2F%3E.Caption%20%3D%20%22New%20Button%22%3CBR%20%2F%3E.OnAction%20%3D%20%22%22%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3EEnd%20If%3CBR%20%2F%3ENext%20r%3CBR%20%2F%3E'Increase%20the%20integer%20to%20move%20to%20the%20next%20instance%3CBR%20%2F%3EWorksheets(%22Sheet1%22).Range(%22F2%22).Value%20%3D%20numb%20%2B%201%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20code%20searches%20a%20range%20and%20places%20a%20button%20where%20ever%20it%20finds%20a%20certain%20string.%20After%20the%20latest%20update%2C%20this%20stopped%20working%20and%20results%20in%20the%20following%20error%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%3CSPAN%3E%22Run-time%20error%20'-2147319765%20(8002802b)'%3A%20Automation%20error%22%3CBR%20%2F%3E%3CBR%20%2F%3EAttached%20is%20a%20spreadsheet%20stripped%20down%20to%20just%20this%20function%2C%20which%20results%20in%20the%20error%20message.%26nbsp%3B%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EPlease%20help!%20I%20wish%20I%20could%20get%20our%20office%20off%20of%20Mac%2C%20but%20they're%20designers%20and%20won't%20budge.%20%3A)%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-236423%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EVba%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-724734%22%20slang%3D%22en-US%22%3ERe%3A%20Excel%20on%20MacOS%20using%20VBA%20to%20create%20a%20button%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-724734%22%20slang%3D%22en-US%22%3EHi%2C%3CBR%20%2F%3EIt's%20been%20some%20time%2C%20did%20you%20fix%20it%3F%3C%2FLINGO-BODY%3E
Rick Argiro
Visitor

I have a spreadsheet that uses a button to create another button. It has worked for the past couple of years up until recently when a couple of systems were updated to Excel 16.16.1 (MacOS). This issue only started occurring on Excel for Mac. Something with the latest revision is breaking the VBA control that allows this to function. 

 

Here's the code:

Sub new_button()
'Click this button to make more buttons
'Numb is an index that increases everytime the button is pressed
Dim numb As Integer
numb = Worksheets("Sheet1").Range("F2").Value
Dim r As Range
'These are the strings that exist on the spreadsheet
Dim verline As String
verline = "New Button Goes Here " & numb

For Each r In Range("D10:D29")
'This will search for the string then add the "New Button" button
If r.Value Like verline Then
With r.Parent.Buttons.Add(r.Left, r.Top, r.Width, r.Height)
.Font.Bold = True
.Caption = "New Button"
.OnAction = ""
End With
End If
Next r
'Increase the integer to move to the next instance
Worksheets("Sheet1").Range("F2").Value = numb + 1
End Sub

 

The code searches a range and places a button where ever it finds a certain string. After the latest update, this stopped working and results in the following error:

"Run-time error '-2147319765 (8002802b)': Automation error"

Attached is a spreadsheet stripped down to just this function, which results in the error message. 

 

Please help! I wish I could get our office off of Mac, but they're designers and won't budge. :)

1 Reply
Hi,
It's been some time, did you fix it?