lezawang
Well-known Member
- Joined
- Mar 27, 2016
- Messages
- 1,805
- Office Version
- 2016
- Platform
- Windows
Hi
The code below opens the other workbook but does not copy the sheet. I got run-time error 9 message. Thank you so much.
Update: I found the answer. I was entering the second workbook name without extension. for example I was entering Book2
but when I entered Book2.xlsx, everything was ok. My question now when I can enter Workbook name without extension and when with extension because I remember sometime I enter the workbook name without extension and it did work? I do not recall which situation. Thank you again.
The code below opens the other workbook but does not copy the sheet. I got run-time error 9 message. Thank you so much.
Code:
Sub sheet_copy_diff_wb()
'to copy sheet to different wb
Dim x As Integer
Dim s As String
x = InputBox("enter sheet# you want to copy")
s = InputBox("enter workbook name you want to copy the sheet to")
Workbooks.Open (s)
Workbooks(1).Worksheets(x).Copy after:=Workbooks(s).Worksheets(1)
Workbooks(s).Save
Workbooks(s).Close
End Sub
Update: I found the answer. I was entering the second workbook name without extension. for example I was entering Book2
but when I entered Book2.xlsx, everything was ok. My question now when I can enter Workbook name without extension and when with extension because I remember sometime I enter the workbook name without extension and it did work? I do not recall which situation. Thank you again.
Last edited: