+ Reply to Thread
Results 1 to 7 of 7

ActiveWorkbook.Worksheets.Name - Apllication-defined or object-defined error

  1. #1
    Registered User
    Join Date
    04-14-2013
    Location
    Lisbon
    MS-Off Ver
    Excel 2003
    Posts
    4

    ActiveWorkbook.Worksheets.Name - Apllication-defined or object-defined error

    Hi folks.
    This is my first post, relalatively new to vba, i'm trying to write a little program that creates sheets from an user box.
    So the user puts the quantity of sheets to be created (ex.-3), then i would like to have 3 new sheets and these sheets renamed with 1, 2, 3 etc
    Works without problem but have a problem when it tries to rename the new worksheets from the array values.
    Therefore if i have an hard coded array i have no problems to rename from these values...

    Please Login or Register  to view this content.
    Here is my code..

    Please Login or Register  to view this content.
    I get an 1004 error "Apllication-defined or object-defined error" at this part.
    Please Login or Register  to view this content.
    If i could have a friendly hand on my code, and maybe some explanations :-) Really would appreciate, i'm getting a bit stucked on it, really i don't see where i'm false...

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: ActiveWorkbook.Worksheets.Name - Apllication-defined or object-defined error

    If you are "new to vba: and wrote this code that is very impressive. The With statement that you used is solid. The problem is with the "theArr(sht)" part. Correct me if I am wrong but don't you want the name of the sheet to be what was entered into the input box? If that is the case why not just use

    Please Login or Register  to view this content.

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: ActiveWorkbook.Worksheets.Name - Apllication-defined or object-defined error

    Hi, CLIOWIWI,

    the array you refer to is redimmed but empty - you should use sht to give the sheet a name:
    Please Login or Register  to view this content.
    And fine art of indenting wouldn´t help with this problem but make the code a lot more readable:
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    04-14-2013
    Location
    Lisbon
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: ActiveWorkbook.Worksheets.Name - Apllication-defined or object-defined error

    Quote Originally Posted by stnkynts View Post
    If you are "new to vba: and wrote this code that is very impressive. The With statement that you used is solid. The problem is with the "theArr(sht)" part. Correct me if I am wrong but don't you want the name of the sheet to be what was entered into the input box? If that is the case why not just use

    Please Login or Register  to view this content.
    Thank you, you're nice fella with my code, but really i've got written vba (or try to understand it) from 3 months, and sometimes what you see from some coders, it's really impressive, and certainly my code, is somewhat, but thank you, really.
    And yes i would rename my recently created sheets with the "names" of the array values...

  5. #5
    Registered User
    Join Date
    04-14-2013
    Location
    Lisbon
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: ActiveWorkbook.Worksheets.Name - Apllication-defined or object-defined error

    Quote Originally Posted by HaHoBe View Post
    Hi, CLIOWIWI,

    the array you refer to is redimmed but empty - you should use sht to give the sheet a name:
    Please Login or Register  to view this content.
    And fine art of indenting wouldn´t help with this problem but make the code a lot more readable:

    Please Login or Register  to view this content.
    Ciao,
    Holger
    You are totally right, i must to take some good coding resolutions to have less problems..
    I Have already tried you're solution, it works indeed, but one of my goals in my program was also, if sheets exists already do not create them, and no error on another execution on the same sheet..
    Please Login or Register  to view this content.
    certainly i don't understand the difference between

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    Thank you lot for give me some time!

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: ActiveWorkbook.Worksheets.Name - Apllication-defined or object-defined error

    Hi, CLIOWIWI,

    maybe you can have a look at this apoproach (no array neede here):
    Please Login or Register  to view this content.
    There are definitely other ways/codes available to achieve the same result.

    Ciao,
    Holger

  7. #7
    Registered User
    Join Date
    04-14-2013
    Location
    Lisbon
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: ActiveWorkbook.Worksheets.Name - Apllication-defined or object-defined error

    Thank You a lot! Works perfectly!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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