VBA Code: Merging worksheets from one workbook to another

suremac

New Member
Joined
Jan 27, 2014
Messages
49
Greetings,

I need to write a macro that merges all the sheets from the ISOHODataCopy1.xls workbook to the zmastertablestest1.xlsm workbook. They are the only two files in the Source_and_Master_Data folder. I have been using this code:

Sub GetISOSheets()
Path = "C:\Users\turner\Desktop\Source_and_Master_Data\"
Filename = Dir(Path & "*.xls")
Do While Filename <> ""
Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
Workbooks(Filename).Close
Filename = Dir()
Loop


End Sub


This vba code sucessfully merges the worksheets to the master workbook, but two error boxes appear.

1. File not found: 'C:\Users\name\AppData\Local\Temp\VBF10tmp
2. Run-time erroe '1004': Copy method of worksheet class failed.

The error occurs at this line of code:
Sheet.Copy After:=ThisWorkbook.Sheets(1)

I want to be able to run this macro and another macro at the same time, but the errors prevent this. How can I resolve these errors?

Thanks!!!
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,215,123
Messages
6,123,182
Members
449,090
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top