Function GetWorksheetFromCodeName(wb As Workbook, CodeName As String) As Worksheet
' Description: Gets worksheet object by its codename
' Inputs: Workbook object, CodeName (string)
' Outputs: Worksheet object if found, otherwise Nothing
'*** Deklarációk ***
Dim ws As Worksheet
'*******************
' check if workbook object exists
If wb is Nothing then Exit Function
' iterate worksheets
For Each ws In wb.Worksheets
If StrComp(ws.CodeName, CodeName, vbTextCompare) = 0 Then
Set GetWorksheetFromCodeName = ws
Exit Function
End If
Next ws
End Function