Tavvkind
08-04-2014, 05:08 AM
Hello all,
I've found a piece of VBA code and I don't understand part of that piece:
Sub Test2()
' rondebruin.nl/win/s9/win002.htm
Dim szSourceWorkbook As String
Dim wkbSource As Excel.Workbook
szSourceWorkbook = ActiveWorkbook.Name
Set wkbSource = Application.Workbooks(szSourceWorkbook)
MsgBox ActiveWorkbook.Name & " " & wkbSource.Name ' Book1 Book1
End Sub
Why would someone get the name of the active workbook and then return the workbook of the same name by using the .Workbooks collection (instead of just doing: Set wkbSource = ActiveWorkbook). When I run the subroutine above, the name of the workbook is the same ("Book1").
I've found a piece of VBA code and I don't understand part of that piece:
Sub Test2()
' rondebruin.nl/win/s9/win002.htm
Dim szSourceWorkbook As String
Dim wkbSource As Excel.Workbook
szSourceWorkbook = ActiveWorkbook.Name
Set wkbSource = Application.Workbooks(szSourceWorkbook)
MsgBox ActiveWorkbook.Name & " " & wkbSource.Name ' Book1 Book1
End Sub
Why would someone get the name of the active workbook and then return the workbook of the same name by using the .Workbooks collection (instead of just doing: Set wkbSource = ActiveWorkbook). When I run the subroutine above, the name of the workbook is the same ("Book1").