S
Shazbot79
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 _
before:=mainbook.Worksheets(1)
importbook.Close savechanges:=False 'closes the import sheet
end sub
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 _
before:=mainbook.Worksheets(1)
importbook.Close savechanges:=False 'closes the import sheet
end sub