![]() |
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. |
copy worksheet to a different workbook
I figured it out ... the strings I was using for filenames included the
complete directory.... sorry. |
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. |
All times are GMT +1. The time now is 05:43 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com