Fully reference a worksheet by codename

后端 未结 5 770
春和景丽
春和景丽 2020-11-28 14:27

When I reference Excel worksheets using the CodeName property, how do I fully qualify them including the workbook reference?

I want to guard against a scenario with

5条回答
  •  旧时难觅i
    2020-11-28 14:59

    Dim wb as Workbook
    Dim ws  as worksheet
    
    Set wb = "Your Workbook full path and name"
    
    For each ws in wb.worksheets
        If ws.codename = "Your Codename" then exit for
        next ws
    
    

    ws will now contain the reference to the worksheet in other workbook with the desired codename with no user changeable dependencies

    Hope this helps

提交回复
热议问题