macro_learning
New Member
Hi All,
Can anyone please help me with the below code,
it should merge all the sheets in all the workbook in any given folder to a workbook "copying1.xlsm". it is opening the file however not copying the sheets to the workbook "copying1.xlsm".
Can anyone please help me with the below code,
it should merge all the sheets in all the workbook in any given folder to a workbook "copying1.xlsm". it is opening the file however not copying the sheets to the workbook "copying1.xlsm".
Code:
Sub copyingsheets()
Application.ScreenUpdating = False
mysourcepath = InputBox("path")
Set myobject = New Scripting.FileSystemObject
Set mysource = myobject.GetFolder(mysourcepath)
On Error Resume Next
For Each myfile In mysource.Files
Workbooks.Open (myfile)
For Each Sheet In Workbooks(myfile).Worksheets
Total = Workbooks("copying1.xlsm").Worksheets.Count
Workbooks(myfile).Worksheets(Sheet.Name).Copy _
after:=Workbooks("copying1.xlsm").Worksheets(Total)
MsgBox myfile.Name ' msgbox is populating name of the workbook myfile correctly
MsgBox Sheet.Name ' msgbox is not populating name of the sheet
MsgBox Total 'msgbox is populating the value of variable "Total" correctly
Next Sheet
Next myfile
Application.ScreenUpdating = True
End Sub
Last edited by a moderator: