ferocious12
Member
Hi All,
I have following macro that extract worksheet "Data entry" from all the excel files saved at a particular location and combine them in one workbook. It was working fine until last month but this month my excel keep crashing when I run the macro and it doesn't do the job.
Can you see any mistake in it. The debugging point me to "SFname" in the following code but don't know:
I have following macro that extract worksheet "Data entry" from all the excel files saved at a particular location and combine them in one workbook. It was working fine until last month but this month my excel keep crashing when I run the macro and it doesn't do the job.
Can you see any mistake in it. The debugging point me to "SFname" in the following code but don't know:
Code:
Sub CombineSheets()
Dim sPath As String
Dim sFname As String
Dim wBk As Workbook
Dim wSht As Variant
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False
sPath = InputBox("Enter a full path to workbooks")
ChDir sPath
sFname = "*"
sFname = Dir(sPath & "\" & sFname & ".xl*", vbNormal)
wSht = "Data entry"
Do Until sFname = ""
Set wBk = Workbooks.Open(sFname)
Windows(sFname).Activate
Sheets(wSht).Copy Before:=ThisWorkbook.Sheets(1)
wBk.Close False
sFname = Dir()
Loop
ActiveWorkbook.Save
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub