I want to find a workbook when the CodeName is in a variable.
If I have the Name in variable sName then
Workbooks(sName) gives me the workbook.
So when the CodeName is in a variable sCodeName, how can I reference the workbook that it belongs to?
I want to find a workbook when the CodeName is in a variable.
If I have the Name in variable sName then
Workbooks(sName) gives me the workbook.
So when the CodeName is in a variable sCodeName, how can I reference the workbook that it belongs to?
Hi foxguy
Perhaps this (untested)Please Login or Register to view this content.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please mark your Thread as SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hello Foxguy,
The Code name for an object can only be found by walking the collection of objects the code name belongs to. In Excel there are only 3 collections have CodeName properties:Charts, Workbooks, and Worksheets. The Active workbook's CodeName is always "ThisWorkbook". Worksheet code names are like Sheet1, Sheet2, Sheet3, etc. Here is an example that assigns an object variable to the object with the CodeName in sName.
Please Login or Register to view this content.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Star below the post.3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Leith;
Thanks for confirming what I already believed.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks