+ Reply to Thread
Results 1 to 18 of 18

Reset object number

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Reset object number

    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.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,311

    Re: Reset object number

    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


  3. #3
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: Reset object number

    Dear TM Shucks,

    I have closed the file and reopen the file again, but the number has not reset.

    Regards

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,311

    Re: Reset object number

    I actually meant close down Excel and restart it, not just close the spreadsheet and re-open it.

    Regards

  5. #5
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: Reset object number

    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.

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,985

    Re: Reset object number

    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.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Reset object number

    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 the icon 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!)

  8. #8
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: Reset object number

    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".

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Reset object number

    Please reread post #7.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,311

    Re: Reset object number

    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

  11. #11
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: Reset object number

    Thanks all.

    I will try to rename the object number by VBA.

    Regards.

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Reset object number

    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.

  13. #13
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: Reset object number

    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.

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Reset object number

    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?

  15. #15
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: Reset object number

    Thanks all,

    I think the easiest way is to rename the object added every time.

    Regards.

  16. #16
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Reset object number

    That is correct. You have answers to the questions I posed?

  17. #17
    Forum Contributor
    Join Date
    09-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Office 365
    Posts
    375

    Re: Reset object number

    Thanks JB,

    You have solved my problem at this moment.
    I'll look into my own VBA application before new posting.

    Regards.

  18. #18
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Reset object number

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1