Hi there,
I am trying to copy some data a file called "Excel Macro.xlsm" to a file called "BCH.xlsx" but cnt seem to manage it.
The original file "Excel Macro.xlsm" contains 2 sheets: master and BCH. I have placed a button in the 'master' sheet which should extract cells A1:E20 from the BCH sheet (in Excel Macro.xlsm) and place it in an unopen Excel file called "BCH.xlsx" which contains just one sheet "BCH".
The code I'm using is as follows:
Sub Demo()
Dim wbSource As Workbook
Dim wbTarget As Workbook
Set wbSource = Workbooks.Open(“c:\Users\Chris\desktop\Excel Macro.xlsm”)
Set wbTarget = Workbooks.Open("c:\Users\Chris\desktop\BCH.xlsx") ' Workbooks.Open(" ")
wbTarget.Sheets("BCH").Range("A1:E20").Value = wbSource.Sheets("BCH").Range("A1:E20")
wbSource.Close
End Sub
Can anyone point me in the right direction - I get a "Syntax Error. Compile error" error message when I run it.
This is the first time Ive tried to do VBA so go easy )
Many thanks in advance
I am trying to copy some data a file called "Excel Macro.xlsm" to a file called "BCH.xlsx" but cnt seem to manage it.
The original file "Excel Macro.xlsm" contains 2 sheets: master and BCH. I have placed a button in the 'master' sheet which should extract cells A1:E20 from the BCH sheet (in Excel Macro.xlsm) and place it in an unopen Excel file called "BCH.xlsx" which contains just one sheet "BCH".
The code I'm using is as follows:
Sub Demo()
Dim wbSource As Workbook
Dim wbTarget As Workbook
Set wbSource = Workbooks.Open(“c:\Users\Chris\desktop\Excel Macro.xlsm”)
Set wbTarget = Workbooks.Open("c:\Users\Chris\desktop\BCH.xlsx") ' Workbooks.Open(" ")
wbTarget.Sheets("BCH").Range("A1:E20").Value = wbSource.Sheets("BCH").Range("A1:E20")
wbSource.Close
End Sub
Can anyone point me in the right direction - I get a "Syntax Error. Compile error" error message when I run it.
This is the first time Ive tried to do VBA so go easy )
Many thanks in advance