View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Shazbot79 Shazbot79 is offline
external usenet poster
 
Posts: 10
Default Copy from one workbook to another failing

I have copied this code pretty much entirely from another post but it
throws up Run time error 9 subscript out of range'. Can anyone help?
Thanks


Public Sub ImportData()
Dim myFilename As Variant
Dim importbook As Workbook
Dim mainbook As Workbook



MsgBox "Please select the Do Not Trace workbook you wish to import."

myFilename = Application.GetOpenFilename("Excel Files (*.xls), *.xls")
'launches prompt to select import file

Set mainbook = ActiveWorkbook

Set importbook = Workbooks.Open(Filename:=myFilename) 'sets variable
to be workbook that opens



importbook.Worksheets("sheet1").Copy _
befo=mainbook.Worksheets(1)


importbook.Close savechanges:=False 'closes the import sheet
end sub