excel - Identifying a worksheet other than by its name -


a worksheet can identified name such in example:

dim mysheet worksheet set mysheet = thisworkbook.sheets("my sheetname") 

now wonder if worksheet can identified other name, example unique id or property or whatever.

my problem following:

referring code snippet above: if user changes name of worksheet (e.g. "my sheetname" "your sheetname"), snippet won't work anymore.

this article explains better use sheetid (also called codename) instead of sheet name.

quoting:

the codename property internal name excel uses identify each sheet. unlike worksheet.name property, codename remains same regardless of sheet name, or sheet order.

the code name can changed more descriptive:

thisworkbook.vbproject.vbcomponents("sheet1").name = "revenue_actuals" 

and then

revenue_actuals.range("c2").value = 10 

works fine.

using codenames (such sheet1.range("c1").value) idea, changing code names at runtime above not considered practice developers (see example, comments on article of link above).

using sheet index way go, prefer code name.

finally, this article lists many ways sheet or workbook can referenced.

i hope helps!


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -