If I already have a workbook open, and know the name of the workbook, why can't I simply assign the workbook to a variable?
Example:
If I have workbook A and workbook B, and both are open.
The code is in workbook A.
Why can't I do something simple like:
It seems like all the ways I have been doing it (as per research and internet) involve more code than what I would assume is needed to simply state:
Variable X is "Workbook B"
Granted the code I have been using works, but I just don't fully understand why ... and why the above snippet wouldn't work ....
I am looking for more of the concept/principle than fixing the above code .... but writing the above code correctly would help with understanding the concept/principle.
-Spydey
Example:
If I have workbook A and workbook B, and both are open.
The code is in workbook A.
Why can't I do something simple like:
Code:
Sub Assign_WB
Dim wb as Workbook
Set wb = Workbooks("Workbook B")
For Each ws In wb.Worksheets
etc etc etc
Next
End Sub
It seems like all the ways I have been doing it (as per research and internet) involve more code than what I would assume is needed to simply state:
Variable X is "Workbook B"
Granted the code I have been using works, but I just don't fully understand why ... and why the above snippet wouldn't work ....
I am looking for more of the concept/principle than fixing the above code .... but writing the above code correctly would help with understanding the concept/principle.
-Spydey