I have a workbook which imports data from two delimited text files. I can import the data with no problems, but I cannot get the delimited files to close after the data has been imported. Can someone look at my code and tell me what is causing this?
Be nice - this is my first attempt at programming in Excel!
MonthName = ActiveSheet.Cells(17, 7).Value
Workbooks.Open "c:\Bryan\Databases\Human Resources\LeaveTaken.txt", , , 4
ActiveWorkbook.ActiveSheet.UsedRange.Copy
Workbooks("HRMonthlyData.xls".Activate
ActiveWorkbook.Worksheets(MonthName & "Leave".Select
ActiveSheet.Paste Destination:=ActiveSheet.Cells(1, 2)
ActiveSheet.Range("A1".Select
Worksheets(MonthName & "Leave".Columns(6).NumberFormat = "@"
ActiveSheet.Cells(1, 1) = "Download Month"
ActiveSheet.Cells(2, 1).Select
Set CurrentCell = ActiveSheet.Cells(2, 1)
Do While Not IsEmpty(CurrentCell.Offset(0, 1))
Set NextCell = CurrentCell.Offset(1, 0)
CurrentCell = Left(MonthName, 3)
Set CurrentCell = NextCell
Loop
Workbooks(Workbooks.Count).Activate
Workbooks(Workbooks.Count).Close SaveChanges:=False '<-- This is not working
'Workbooks("Leavetaken.txt".Close (False) '<--- Neither does this
Workbooks("HRMonthlyData.xls".Activate
ActiveWorkbook.Worksheets("Menu Sheet".Select
MonthName = ""
ActiveWorkbook.Save
As you can see, I've tried various ways to close the file, but none of them are closing the file.
Can anyone help?
Thanks in advance
Lightning
Be nice - this is my first attempt at programming in Excel!
MonthName = ActiveSheet.Cells(17, 7).Value
Workbooks.Open "c:\Bryan\Databases\Human Resources\LeaveTaken.txt", , , 4
ActiveWorkbook.ActiveSheet.UsedRange.Copy
Workbooks("HRMonthlyData.xls".Activate
ActiveWorkbook.Worksheets(MonthName & "Leave".Select
ActiveSheet.Paste Destination:=ActiveSheet.Cells(1, 2)
ActiveSheet.Range("A1".Select
Worksheets(MonthName & "Leave".Columns(6).NumberFormat = "@"
ActiveSheet.Cells(1, 1) = "Download Month"
ActiveSheet.Cells(2, 1).Select
Set CurrentCell = ActiveSheet.Cells(2, 1)
Do While Not IsEmpty(CurrentCell.Offset(0, 1))
Set NextCell = CurrentCell.Offset(1, 0)
CurrentCell = Left(MonthName, 3)
Set CurrentCell = NextCell
Loop
Workbooks(Workbooks.Count).Activate
Workbooks(Workbooks.Count).Close SaveChanges:=False '<-- This is not working
'Workbooks("Leavetaken.txt".Close (False) '<--- Neither does this
Workbooks("HRMonthlyData.xls".Activate
ActiveWorkbook.Worksheets("Menu Sheet".Select
MonthName = ""
ActiveWorkbook.Save
As you can see, I've tried various ways to close the file, but none of them are closing the file.
Can anyone help?
Thanks in advance
Lightning