I have two Workbooks one named master and the other slave.
I have created a macro to copy a range of data from a sheet named DATA in the master workbook to a sheet called DataCopyMaster in the slave workbook and then make the Records sheet active before saving and closing the slave workbook, which all works fine. I wanted to add this to the BeforeClose event of the master workbook so I can ensure the slave updates every time the master is closed but nolonger works once added to the BeforeClose event.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
When I close the Master workbook I get a Visual basic runtime error runtime error ‘9’
Script out of range
It appears to code runs to the line:
<o> </o>
Below is the macro I'm using in full.
<o> </o>
<o> </o>
I don’t have a lot of experience with coding and I am sure I’m missing something simple here but would appreciate any assistance.
TB.
I have created a macro to copy a range of data from a sheet named DATA in the master workbook to a sheet called DataCopyMaster in the slave workbook and then make the Records sheet active before saving and closing the slave workbook, which all works fine. I wanted to add this to the BeforeClose event of the master workbook so I can ensure the slave updates every time the master is closed but nolonger works once added to the BeforeClose event.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o> </o>
When I close the Master workbook I get a Visual basic runtime error runtime error ‘9’
Script out of range
It appears to code runs to the line:
Code:
Sheets("DataCopyMaster").Select
Below is the macro I'm using in full.
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Range("A1:M50").Select
Selection.Copy
ChDir "C:\DATA\My Documents"
Workbooks.Open Filename:="C:\DATA\My Documents\TestSheetSlave.xls"
Sheets("DataCopyMaster").Select
Range("A1:M50").Select
ActiveSheet.Paste
Range("A1").Select
Sheets("Records").Select
ActiveWorkbook.Save
ActiveWindow.Close
Application.CutCopyMode = False
Range("A1").Select
End Sub
<o> </o>
I don’t have a lot of experience with coding and I am sure I’m missing something simple here but would appreciate any assistance.
TB.