Referencing sheets in another workbook by codename using VBA [duplicate]

You can "hack" a reference to another workbook sheet code name by:

Sub UseCodeNameFromOutsideProject()
    Dim WS As Worksheet
    With Workbooks("InputBook .xls")
        Set WS = _
            .Worksheets(CStr(.VBProject.VBComponents("Lines").Properties(7)))
        debug.print WS.Name
    End With
 End Sub

Your WS object is now set to the sheet which has the codename "Lines" in this example.


Original inspiration is here.