When I insert an object, excel will assign a new number.
How can I reset such number to 1 after deleting all existing objects?
When I insert an object, excel will assign a new number.
How can I reset such number to 1 after deleting all existing objects?
Last edited by london7871; 10-19-2011 at 01:25 AM.
I suspect that you'd have to shut down Excel and open it up again. Unless the object number is stored somewhere within the workbook, that should clear it.
No guarantees but worth a try.
Regards
Trevor Shuttleworth - Retired Excel/VBA Consultant
I dream of a better world where chickens can cross the road without having their motives questioned
'Being unapologetic means never having to say you're sorry' John Cooper Clarke
Dear TM Shucks,
I have closed the file and reopen the file again, but the number has not reset.
Regards
I actually meant close down Excel and restart it, not just close the spreadsheet and re-open it.
Regards
My case is:
My excel have 4 objects with 4 numbers.
When I insert new object, the number is 5.
When I delete this object No.5, how to keep the new object number = 5?
(without "close down Excel and restart it")
NB: I have close the excel file and turn off and on computer; but the number has not reset.
Is there a reason you can't just rename the object?
The short answer is that you cannot reset excel's internal counter without a restart, and apparently even that doesn't work for you anyway.
Last edited by romperstomper; 10-13-2011 at 03:18 AM.
Everyone who confuses correlation and causation ends up dead.
In VBA you need a consistent way to address objects. Excel lets you refer to them by their "excel determined" index number (Object(1), Sheet(1), etc...) or by their name.
If your environment has you adding and deleting objects regularly, I would never try to use Excel's index numbers to refer to them. I would take control of how the objects are added and named, then refer to them by name all the time.
If I needed to replace my Object named "Object1" in VBA, I would:
1) First delete the existing "Object1" object
2) Add a new replacement object
3) Rename it immediately to "Object1" while I still have control of the temp object
Now I have permanent control of that object.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
I have 4 objects with 4 numbers and if I delete a newly added object (No.5),
the following new object is No.6.
If I rename this object as No. 5 , the following new object is No.7, instead of No. 6.
I want to keep the numbering consistent as my VBA will apply to these objects.
My new query is how to "reset excel's internal counter".
Please reread post #7.
I think the consensus is that you cannot control Excel's internal numbering system/process ... so you need to work with it.
Perhaps you could share your code and someone may then be able to advise you how best to cope with the situation.
As JB has said, it is best to control the naming yourself so you know to what you are referring with no ambiguity.
Regards
Thanks all.
I will try to rename the object number by VBA.
Regards.
I hope you're not misunderstanding my point in post #7. I'm saying to name your objects something unique, then control them via that unique name.
1) Delete the object named "MyObjectCat"
2) Add a new object
3) Rename the object to "MyObjectCat" while you still have temporary control of the object regardless of object index number
Continue to control the object by it's name.
Dear TM,
There are 4 objects with number 1,2,3,4 and I delete new object No.5.
I think you mean:
When I add a new object (assigned by Excel as No.6), I rename it as No.5.
However,
the following new object is No.7 and hence I have to rename everytime I add new object.
Regards.
The trick is to think of them by name. Well, and make sure you have control of the NEW object as you add it. Declare an object variable. Then set that object in the "add object" command so the new object is referenced in the known variable, even though the object itself might be object99 at this particular moment. By setting the variable reference at the same time you add the object, you already have control off it.... rename it something you can control permanently despite the index number of 99.
What is the code you use to delete the object currently?
What is the code you use to add an object to your sheet?
Thanks all,
I think the easiest way is to rename the object added every time.
Regards.
That is correct. You have answers to the questions I posed?
Thanks JB,
You have solved my problem at this moment.
I'll look into my own VBA application before new posting.
Regards.
If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks