-
Get Workbook Index from VBA
Hello,
I know that you can use
[VBA]Workbooks.Item(l)
'or
Workbooks(l)[/VBA]
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?
[VBA]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[/VBA]
-
I've never used Index with workbooks. I'd rather use variables set to the named book to avoid possible confusion.
For the current book you can simply use
[VBA]Set wb = ThisWorkbook
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
It is hard to explain, by I need this property on my project. I think I'll just keep using my custom function.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules