Ninja Dude
Ninja Dude

Reputation: 1392

VBComponent refer to sheet by tab name

Set VBProj = ActiveWorkbook.VBProject
        Set VBComp = VBProj.VBComponents("Sheet10")

I have the code above. Currently Sheet10 is named as SummaryTab in the excel tab. I want to refer to the VBComponent using the name in the excel tab. Meaning that I want to use something like

Set VBComp = VBProj.VBComponents("SummaryTab")

However, the above code is giving me errors. how can I fix this?

Upvotes: 4

Views: 2841

Answers (1)

YowE3K
YowE3K

Reputation: 23984

You can use

Set VBComp = VBProj.VBComponents(Worksheets("SummaryTab").CodeName)

Upvotes: 7

Related Questions