Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default copy worksheet to a different workbook

I'm trying to copy the sheets in one workbook into another workbook
using VBA, but I get an error when I try

Sub MergeWorkbooks(strBook1 As String, strBook2 As String)

Dim ws As Worksheet
For Each ws In Workbooks(strBook2).Sheets
ws.Copy Befo=Workbooks(strBook1).Sheets(1)
Next ws

End Sub

Both workbooks are opened when I call them. Any ideas? Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default copy worksheet to a different workbook

I figured it out ... the strings I was using for filenames included the
complete directory.... sorry.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default copy worksheet to a different workbook

Hi Dave

How are you calling this macro, what is the error message you are
getting and what line of code is generating the error? This worked fine
for me:

Sub start()
Dim strBook1 As String
Dim strBook2 As String
strBook1 = "Book3.xls"
strBook2 = "File5.xls"
Call MergeWorkbooks(strBook1, strBook2)
End Sub


Sub MergeWorkbooks(strBook1 As String, strBook2 As String)

Dim ws As Worksheet
For Each ws In Workbooks(strBook2).Sheets
ws.Copy Befo=Workbooks(strBook1).Sheets(1)
Next ws

End Sub

Regards
Rowan

Dave B wrote:
I'm trying to copy the sheets in one workbook into another workbook
using VBA, but I get an error when I try

Sub MergeWorkbooks(strBook1 As String, strBook2 As String)

Dim ws As Worksheet
For Each ws In Workbooks(strBook2).Sheets
ws.Copy Befo=Workbooks(strBook1).Sheets(1)
Next ws

End Sub

Both workbooks are opened when I call them. Any ideas? Thanks.

Reply
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 worksheet from one workbook to a master workbook mvannatta Excel Worksheet Functions 3 April 15th 09 08:32 PM
Copy Worksheet from one Workbook to another Workbook Autumn Dreams Excel Discussion (Misc queries) 5 September 12th 08 10:55 PM
Copy Data from Workbook into specific Worksheet in other Workbook? kingdt Excel Discussion (Misc queries) 1 March 16th 06 06:55 PM
How do I copy a worksheet form a workbook in my workbook Neil Atkinson Excel Programming 1 October 12th 05 12:23 PM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM


All times are GMT +1. The time now is 03:45 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"