O
Otto Moehrbach
Excel XP, Win XP
The code below does as follows:
Opens the "....MASTER..." file.
Loops through 22 files in the C:\Temp folder.
Opens each file.
Copies the lone sheet to the MASTER file.
Closes each file.
The MASTER file is left open (like I want).
It all works fine.
Problem: The Project Explorer window in the VBE shows that the LAST of the
22 files is still open. I cannot access the file in any way that I know of.
The fact that the file is open does not bother my project in any way. I can
close that file only by closing Excel.
Question: Why is that lone last file open (in the VBE)?
Thanks for your time. Otto
Sub CombineBooks()
ThePath = "C:\Temp\"
Set MASTERwb = Workbooks.Open(ThePath & "Daily Error report
MASTER.xls")
ChDir ThePath
TheFile = Dir("*.csv")
Do While TheFile <> ""
If LCase(TheFile) <> LCase("Daily Error report MASTER.xls") Then
Application.DisplayAlerts = False
Set wb = Workbooks.Open(ThePath & "\" & TheFile)
Application.DisplayAlerts = True
wb.Worksheets(1).Copy Before:=MASTERwb.Worksheets(1)
MASTERwb.Worksheets(1).Name = Left(TheFile, Len(TheFile) -
4)
wb.Close SaveChanges:=False
End If
TheFile = Dir
Loop
End Sub
The code below does as follows:
Opens the "....MASTER..." file.
Loops through 22 files in the C:\Temp folder.
Opens each file.
Copies the lone sheet to the MASTER file.
Closes each file.
The MASTER file is left open (like I want).
It all works fine.
Problem: The Project Explorer window in the VBE shows that the LAST of the
22 files is still open. I cannot access the file in any way that I know of.
The fact that the file is open does not bother my project in any way. I can
close that file only by closing Excel.
Question: Why is that lone last file open (in the VBE)?
Thanks for your time. Otto
Sub CombineBooks()
ThePath = "C:\Temp\"
Set MASTERwb = Workbooks.Open(ThePath & "Daily Error report
MASTER.xls")
ChDir ThePath
TheFile = Dir("*.csv")
Do While TheFile <> ""
If LCase(TheFile) <> LCase("Daily Error report MASTER.xls") Then
Application.DisplayAlerts = False
Set wb = Workbooks.Open(ThePath & "\" & TheFile)
Application.DisplayAlerts = True
wb.Worksheets(1).Copy Before:=MASTERwb.Worksheets(1)
MASTERwb.Worksheets(1).Name = Left(TheFile, Len(TheFile) -
4)
wb.Close SaveChanges:=False
End If
TheFile = Dir
Loop
End Sub