Forum Discussion
Poly2021
Sep 29, 2021Copper Contributor
VBA macros for copy and pasting files from one workbook to another
Hi Team,
I'm new with VBA macros and I'm struggling with completing a macro code to automate the copy and pasting of data from one workbook to another. I think I got the code for copying, but I'm having issues with pasting the file. Here's the code:
Workbooks.Open "Source File.xlsx"
Application.Goto Workbooks("Source File.xlsx").Sheets("Apple").Range("A1:A1")
Application.Goto _
Workbooks("Source File.xlsx").Sheets("Apple").Range("A1", "A1")
Cells.Select
Selection.Copy
End Sub
So my plan is to copy worksheet "apple" from workbook "source file" and paste it to worksheet "banana" which is on another workbook. We can name that workbook as "destination file". Hoping for your positive feedback. Thank you so much.
2 Replies
Sort By
It could look like this:
Sub CopyData() Dim wbkSource As Workbook Dim wbkTarget As Workbook Set wbkSource = Workbooks.Open("Source File.xlsx") Set wbkTarget = Workbooks.Open("Destination File.xlsx") wbkSource.Worksheets("Apple").Range("A1").Copy _ Destination:=wbkTarget.Worksheets("Banana").Range("A1") Application.CutCopyMode = False End Sub
- Poly2021Copper ContributorThanks. I will try this one tomorrow. Its late now here in my place. I really appreciate this a lot.