LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy code failing LiAD Excel Programming 2 November 5th 09 07:36 AM
Macros failing when workbook is in shared mode M Hanlon Excel Programming 1 September 27th 08 04:04 AM
copy method of object failing vj2india Excel Programming 0 April 20th 06 02:21 AM
loop through a column on a workbook copying data on each row to another workbook, then copy data back to the original workbook burl_rfc Excel Programming 1 April 1st 06 08:48 PM
Excel Copy Method Failing. [email protected] Excel Programming 2 May 11th 05 06:01 PM


All times are GMT +1. The time now is 08:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"