copy from one book to another

  • Thread starter Thread starter portroe
  • Start date Start date
P

portroe

anybody an idea why I receive a run time error with the below code,?


Sub copy()
Windows("book_master.xls").Activate
Range("A1").Select
Selection.CurrentRegion.Select
Selection.Copy
Workbooks(newWorkBook).Activate
Range("A1").Select
ActiveSheet.Paste
End Sub


I have declared the workbook as a variable

Public newWorkBook As Excel.Workbook



thanks

portroe
 
declaring the variable doesn't set it to anything..
try this:
***********

Public newWorkBook As Excel.Workbook

Sub copy()
Windows("book1").Activate
Range("A1").Select
Selection.CurrentRegion.Select
Selection.copy

Set newWorkBook = Application.Workbooks.Add
newWorkBook.Activate


Range("A1").Select
ActiveSheet.Paste
End Sub
 
Public newWorkBook As Excel.Workbook

Sub copy()
Set newWorkBook = Application.Workbooks.Add

this code copies current region
Workbooks("book2").Sheets("Sheet1").Range("A1").CurrentRegion.cop
Destination:=newWorkBook.Sheets("sheet1").Range("a1")

this code copies all cells
Workbooks("book2").Sheets("Sheet1").Cells.cop
Destination:=newWorkBook.Sheets("sheet1").Range("a1")


End Su
 
Back
Top