Elena Margulis
New Member
- Joined
- Aug 21, 2020
- Messages
- 25
- Office Version
- 365
- Platform
- Windows
I have Book1 workbook with some dataset inside (it can be any records amount dataset), but always starts from cell A1
I need to copy the content of the Book1, which is located in Sheet1 into my other workbook Book2, Sheet1 using macro or vba - by pressing any short key (when macro will be executed)
I was trying to use the following code (advice from another site + research), but having an error - Microsoft Visual Basic for Application, 400
Please, help...
I need to copy the content of the Book1, which is located in Sheet1 into my other workbook Book2, Sheet1 using macro or vba - by pressing any short key (when macro will be executed)
I was trying to use the following code (advice from another site + research), but having an error - Microsoft Visual Basic for Application, 400
Please, help...
VBA Code:
Option Explicit
Sub OpenWorkbook()
Dim swb As Workbook
Set swb = Workbooks.Open("E:\Projects\AAA\Book1.xlsx")
Dim sws As Worksheet: Set sws = swb.Worksheets("Sheet1")
Dim srg As Range: Set srg = sws.Range("All Data")
Dim dwb As Workbook
Set dwb = Workbooks.Open("E:\Projects\AAA\Book2.xlsm")
Dim dws As Worksheet: Set dws = dwb.Worksheets("Sheet1")
Dim dCell As Range: Set dCell = dws.Range("A1")
srg.Copy dCell
swb.Close SaveChanges:=False
dwb.Save
End Sub
Last edited: