lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
In the code below, this line of code
Not sure why I need "Set closedBook". Let say I have one Workbook open, which is Workbooks(1). If I do this code
Without "Set closeBook", would that guarantee that the second workbook is going to be Workbooks(2)?
If yes, then why I need to do "Set closedBook"
Another question please, why he did not define
Source: https://www.automateexcel.com/vba/copy-worksheet/
In the code below, this line of code
Code:
Set closedBook = Workbooks.Open("D:\Dropbox\excel\articles\example.xlsm")
Not sure why I need "Set closedBook". Let say I have one Workbook open, which is Workbooks(1). If I do this code
Code:
Workbooks.Open("D:\Dropbox\excel\articles\example.xlsm")
Without "Set closeBook", would that guarantee that the second workbook is going to be Workbooks(2)?
If yes, then why I need to do "Set closedBook"
Another question please, why he did not define
Code:
Dim ClosedBook as Workbook
Code:
Sub CopySheetToClosedWB()
Application.ScreenUpdating = False
Set closedBook = Workbooks.Open("D:\Dropbox\excel\articles\example.xlsm")
Sheets("Sheet1").Copy Before:=closedBook.Sheets(1)
closedBook.Close SaveChanges:=True
Application.ScreenUpdating = True
End Sub
Source: https://www.automateexcel.com/vba/copy-worksheet/