Benzadeus
12-05-2011, 12:25 PM
Hello,
I know that you can use
Workbooks.Item(l)
'or
Workbooks(l)
to set reference to a specific Workbook. But the Workbook object hasn't the Item (neither Index) property. Is there a way to get directly a Workbook's index instead of using my workaround below?
Sub Exemplo()
Debug.Print ÍndiceWB(ThisWorkbook)
End Sub
Private Function ÍndiceWB(wb As Workbook) As Long
Dim l As Long
For l = 1 To Workbooks.Count
If Workbooks(l).FullName = wb.FullName Then
ÍndiceWB = l
Exit Function
End If
Next l
End Function
I know that you can use
Workbooks.Item(l)
'or
Workbooks(l)
to set reference to a specific Workbook. But the Workbook object hasn't the Item (neither Index) property. Is there a way to get directly a Workbook's index instead of using my workaround below?
Sub Exemplo()
Debug.Print ÍndiceWB(ThisWorkbook)
End Sub
Private Function ÍndiceWB(wb As Workbook) As Long
Dim l As Long
For l = 1 To Workbooks.Count
If Workbooks(l).FullName = wb.FullName Then
ÍndiceWB = l
Exit Function
End If
Next l
End Function