Hi All,
First time user. I have the following macro below which splits the same tab from multiple workbooks and copies them into a single workbook. I have a file directory location as highlighted below which stores all the excel files that i want to split into one sheet but for some reason the macro does not read the file location correctly and only splits out the excel files in my documents.
Please could any one help with this.
Thanks in advance
Sub CopySameSheetFrmWbs()
Dim wbOpen As Workbook
Dim wbNew As Workbook
'Change Path
Const strPath As String = "\\knahsvr\Finance Common\SSP\Payroll\1 LANCASHIRE\December 2017 - Dummy run v2\Support workers"
Dim strExtension As String
'Comment out the 3 lines below to debug
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
On Error Resume Next
ChDir strPath
'Change extension
strExtension = Dir("*.xls")
Set wbNew = Workbooks.Add
'Change Path, Name and File Format
wbNew.SaveAs Filename:="\\knahsvr\Finance Common\SSP\Payroll\1 LANCASHIRE\December 2017 - Dummy run v2\All employees", FileFormat:=xlWorkbookNormal
Do While strExtension <> ""
Set wbOpen = Workbooks.Open(strPath & strExtension)
With wbOpen
.Sheets("Summary").Copy After:=wbNew.Sheets(wbNew.Sheets.Count)
wbNew.Sheets(wbNew.Sheets.Count).Name = wbNew.Sheets(wbNew.Sheets.Count).Cells(1, 1)
.Close SaveChanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
On Error GoTo 0
End Sub
First time user. I have the following macro below which splits the same tab from multiple workbooks and copies them into a single workbook. I have a file directory location as highlighted below which stores all the excel files that i want to split into one sheet but for some reason the macro does not read the file location correctly and only splits out the excel files in my documents.
Please could any one help with this.
Thanks in advance
Sub CopySameSheetFrmWbs()
Dim wbOpen As Workbook
Dim wbNew As Workbook
'Change Path
Const strPath As String = "\\knahsvr\Finance Common\SSP\Payroll\1 LANCASHIRE\December 2017 - Dummy run v2\Support workers"
Dim strExtension As String
'Comment out the 3 lines below to debug
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
On Error Resume Next
ChDir strPath
'Change extension
strExtension = Dir("*.xls")
Set wbNew = Workbooks.Add
'Change Path, Name and File Format
wbNew.SaveAs Filename:="\\knahsvr\Finance Common\SSP\Payroll\1 LANCASHIRE\December 2017 - Dummy run v2\All employees", FileFormat:=xlWorkbookNormal
Do While strExtension <> ""
Set wbOpen = Workbooks.Open(strPath & strExtension)
With wbOpen
.Sheets("Summary").Copy After:=wbNew.Sheets(wbNew.Sheets.Count)
wbNew.Sheets(wbNew.Sheets.Count).Name = wbNew.Sheets(wbNew.Sheets.Count).Cells(1, 1)
.Close SaveChanges:=False
End With
strExtension = Dir
Loop
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
On Error GoTo 0
End Sub