gssachin
Board Regular
- Joined
- Nov 14, 2013
- Messages
- 155
Dear All,
I am trying to open a new workbook and then copy date from main sheet to newly open workbook but getting error at
"Workbooks(wname).Activate" as "subscript out of range"
how to solve this.... I used workbook (2) instead of wname and its work but following macro not working..
Sub nworkbook()
Dim wname As String
wname = InputBox("Type here New File Name")
Workbooks.Add
ActiveWorkbook.SaveAs "C:\Users\Downloads\Excel_Training" & wname
ThisWorkbook.Activate
Sheet1.Activate
'Range("a1", Range("a1").End(xlDown).End(xlToRight)).Copy
Range("a1").CurrentRegion.Copy
Workbooks(wname).Activate
Range("a1").PasteSpecial (xlPasteColumnWidths)
Range("a1").PasteSpecial (xlPasteAll)
Workbooks(wname).Save
Workbooks(wname).Close
End Sub
I am trying to open a new workbook and then copy date from main sheet to newly open workbook but getting error at
"Workbooks(wname).Activate" as "subscript out of range"
how to solve this.... I used workbook (2) instead of wname and its work but following macro not working..
Sub nworkbook()
Dim wname As String
wname = InputBox("Type here New File Name")
Workbooks.Add
ActiveWorkbook.SaveAs "C:\Users\Downloads\Excel_Training" & wname
ThisWorkbook.Activate
Sheet1.Activate
'Range("a1", Range("a1").End(xlDown).End(xlToRight)).Copy
Range("a1").CurrentRegion.Copy
Workbooks(wname).Activate
Range("a1").PasteSpecial (xlPasteColumnWidths)
Range("a1").PasteSpecial (xlPasteAll)
Workbooks(wname).Save
Workbooks(wname).Close
End Sub
Last edited: