lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
I want to open an closed excel file (abc.xlsx) and then move/copy sheet from the current workbook to that file (abc.xlsx). With your help, I learnt how to do that. But I just found that, when I open the file using open() function, excel will consider that file as workbooks(2). If that is the case, then why I need this line of code below? why I need to set it to X? I can work on it using workbooks(2) object
I want to open an closed excel file (abc.xlsx) and then move/copy sheet from the current workbook to that file (abc.xlsx). With your help, I learnt how to do that. But I just found that, when I open the file using open() function, excel will consider that file as workbooks(2). If that is the case, then why I need this line of code below? why I need to set it to X? I can work on it using workbooks(2) object
Code:
[INDENT]' why I need to assign it to x
set x = application.workbooks.open("c:\abc.xlsx")[/INDENT]
Code:
Sub abc()
Dim x As Workbook
Dim y As String
y = InputBox("enter file name")
Set x = Application.Workbooks.Open(y)
workbooks(1).sheets(1).copy before:= x.sheets(1)
'i can use workbooks(2) instead of x
Workbooks(2).Close
End Sub
Last edited: