Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I figured it out ... the strings I was using for filenames included the
complete directory.... sorry. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Copy worksheet from one workbook to a master workbook | Excel Worksheet Functions | |||
Copy Worksheet from one Workbook to another Workbook | Excel Discussion (Misc queries) | |||
Copy Data from Workbook into specific Worksheet in other Workbook? | Excel Discussion (Misc queries) | |||
How do I copy a worksheet form a workbook in my workbook | Excel Programming | |||
copy worksheet from closed workbook to active workbook using vba | Excel Worksheet Functions |