Macro Question

Ads Patz

New Member
Joined
Jan 12, 2018
Messages
15
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
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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