+ Reply to Thread
Results 1 to 10 of 10

Change Sheet CodeName and try to access it during running code does not work

  1. #1
    Registered User
    Join Date
    04-23-2015
    Location
    Germany
    MS-Off Ver
    2010 & 2013
    Posts
    5

    Question Change Sheet CodeName and try to access it during running code does not work

    Dear all,

    I have the following problem:

    1. Within my Excel-VBA-Code I refer to the internal code name of a sheet (e.g. Calculation. Range(rgRange))
    2. If the user changes the sheet for which I programmed the reference “Calculation” I change the internal code name via ActiveWorkbook.VBProject.VBComponents(wsPVK1.CodeName).Name = "Calculation" (and provide the original sheet with another CodeName before)

    Everything works fine until I want to access Calculation.xxx in the same procedure directly after changing it. The CodeName remains the same as before and the change becomes only valid after starting the/a procedure again.

    What to do to make changes valid immediately?
    Recompile within running code? (How?)
    Wait for completion of change? (How?)

    Thank you for ideas…

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Change Sheet CodeName and try to access it during running code does not work

    Hi Anke,

    Can you provide more of the code? I'm having trouble understanding what exactly is happening.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Change Sheet CodeName and try to access it during running code does not work

    If the user changes the name of a worksheet it doesn't change the codename so I don't see why you need to change the codename.

    As for compiling/recompling while running, pretty sure that's not going to be possible.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    04-23-2015
    Location
    Germany
    MS-Off Ver
    2010 & 2013
    Posts
    5

    Re: Change Sheet CodeName and try to access it during running code does not work

    OK,
    the whole code of the workbook contains more than 500 lines of code, so I cannot provide it to you. But I try to explain my problem better.

    I have several worksheets where the code refers to the internal codename “Calculation”. However, the user can duplicate this sheet (also several times), rename it, etc. BUT only one of these duplicated sheets can serve as input for the code.

    So I programed a UserForm in which the user can select the valid sheet. Since I use “Calculation” as internal CodeName in my program, I have to change the internal CodeName of the selected sheet to “Calculation”.

    However: this change is not valid during the currently running code. Its becomes only valid, if I start the Sub or another Sub again!!

    Hope, you can follow my explanations

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Change Sheet CodeName and try to access it during running code does not work

    Sorry I don't follow.

    If a user copies the sheet with the codename 'Calculation' then the new sheet will not have the codename 'Calculation.

    If the user changes the name of the sheet with the codename 'Calculation' then the codename of that sheet will not change.

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Change Sheet CodeName and try to access it during running code does not work

    Yes Anke, I guess what I wondered is whether you are defining or setting a variable to use the sheet. If you are doing that based on code name and then change the code name, you'd have to refresh your variable again as it would otherwise reference the old name and no longer be valid.

  7. #7
    Registered User
    Join Date
    04-23-2015
    Location
    Germany
    MS-Off Ver
    2010 & 2013
    Posts
    5

    Thumbs up Re: Change Sheet CodeName and try to access it during running code does not work

    Hi Arkadi,
    yes, why complicated if it works easy

    This idea stepped in my brain yesterday night also...

    Anke

  8. #8
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Change Sheet CodeName and try to access it during running code does not work

    I don't really know why you are using the codename here at all since this situation doesn't fit the whole purpose of using the codename.
    Remember what the dormouse said
    Feed your head

  9. #9
    Registered User
    Join Date
    04-23-2015
    Location
    Germany
    MS-Off Ver
    2010 & 2013
    Posts
    5

    Re: Change Sheet CodeName and try to access it during running code does not work

    Why? In the first Version of my Excel only ONE sheet was allowed and Independent of renaming through the user I could Access it thrue its CodeName "Calucaltion". Now users are allowed to have several Sheets and they can rename them all! and select which sheet should be input-sheet for the program. In consequence I am no more able to adress data in this sheet by its Codename.

    This is my Explanation. If I was wrong, please explain.

  10. #10
    Registered User
    Join Date
    04-23-2015
    Location
    Germany
    MS-Off Ver
    2010 & 2013
    Posts
    5

    Re: Change Sheet CodeName and try to access it during running code does not work

    P.S.: now I will store the CodeName of a selected sheet, retrieve the current Name (Independent of renaming ist in between) and address the selected sheet by its Name (since it is not possible to address it vial variable CodeName)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Selecting sheet by codename in a multi sheet code
    By jshaw82 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-18-2013, 10:46 AM
  2. Opening Excel from Access, running Code in Excel then export back to Access
    By JungleJme in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-28-2012, 08:49 AM
  3. Running excel vba code from inside access vba code
    By Lanox in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 08-31-2011, 09:09 AM
  4. [SOLVED] change sheet codename
    By Gary Keramidas in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-04-2006, 09:00 PM
  5. Replies: 1
    Last Post: 07-07-2005, 10:05 PM

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