B
biojunkie
Hi All,
I am using this macro to automatically copy worksheets from other files
to this file.
This has the code for automatically naming the new worksheets with the
count number when a worksheet of the same name already exists in the
file.
I want to take off this feature. I want the macro to overwrite the
sheets without uniquely naming the new sheets
I tried taking off the two lines of code. . but it gives me errors.
Can somebody help me. .
Here is the code.
Option Explicit
Sub CombineFiles()
Dim Path As String
Dim FileName As String
Dim Wkb As Workbook
Dim WS As Worksheet
Application.EnableEvents = False
Application.ScreenUpdating = False
Path = "C:\Documents and Settings\Desktop"
FileName = Dir(Path & "\*.xls", vbNormal)
Do Until FileName = ""
Set Wkb = Workbooks.Open(FileName:=Path & "\" & FileName)
For Each WS In Wkb.Worksheets
WS.Copy
After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Next WS
Wkb.Close False
FileName = Dir()
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
I am using this macro to automatically copy worksheets from other files
to this file.
This has the code for automatically naming the new worksheets with the
count number when a worksheet of the same name already exists in the
file.
I want to take off this feature. I want the macro to overwrite the
sheets without uniquely naming the new sheets
I tried taking off the two lines of code. . but it gives me errors.
Can somebody help me. .
Here is the code.
Option Explicit
Sub CombineFiles()
Dim Path As String
Dim FileName As String
Dim Wkb As Workbook
Dim WS As Worksheet
Application.EnableEvents = False
Application.ScreenUpdating = False
Path = "C:\Documents and Settings\Desktop"
FileName = Dir(Path & "\*.xls", vbNormal)
Do Until FileName = ""
Set Wkb = Workbooks.Open(FileName:=Path & "\" & FileName)
For Each WS In Wkb.Worksheets
WS.Copy
After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count)
Next WS
Wkb.Close False
FileName = Dir()
Loop
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub