Button/Object ID Incrementing Beyond 65537

InsatiableAmos

New Member
Joined
Jan 7, 2010
Messages
8
I've got a workbook that's used in a pretty unusual way - it's a dynamic set of checklists with buttons that do things for the checklist operator based on parameters they've selected. We've been updating this workbook since it's inception a few years ago, and one of the best parts about it is that it deletes all currently-occurring command buttons and sets them up anew every time the user selects different parameters.

The problem is that Excel assigns a incremental ID number to every button we've ever created within that workbook, and even though we rename all the Buttons on creation, we've finally hit the maximum number of buttons excel allows!

We can copy everything into a new workbook, code and all, but that seems silly, temporary, and it's a pain. We can also refactor the code such that it hides/reuses buttons instead of deleting/recreating them, but that's a large undertaking for folks that don't necessarily know VBA too well (i won't be able to make the changes myself).

Is there a way to reset the incremental object count within a workbook? Just this tweak would solve our problem, and it would merely be a one-line add to reset that number every time the workbook was opened.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
No ideas? Here is some relevant code...

Code that makes the buttons:
Code:
Public Sub MakeSaveButton(StepNum As Long)
If StepNum > 0 Then

    Dim l, T As Long

    l = 0
    T = 0

    targetCell = "F" & StepNum * 4 + 9

    With Range(targetCell)
        l = .Left
        T = .Top
    End With


        ActiveSheet.Buttons.Add(l, T, 73, 13).Select
        With Selection
            .Characters.Text = "Button Name"
            .OnAction = "SaveChecklist"
        End With

Else

End If

End Sub

What happens is that when the number of unique button IDs runs out, the line "ActiveSheet.Buttons.Add(l, T, 73, 13).Select" creates a new button named "Button 65537"

When the "With Selection" statement tries to select it, i get an error 1004 because it can't select a button numbered that high.

I certainly don't ever have 65536 buttons alive and present at once, and i delete them often, i just can't clear or restart the workbook incrementer for object numbers.

And just for reference, this is how i delete the buttons:
Code:
Public Sub DeleteButtons()

    ActiveSheet.Buttons.Delete

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top