Closing multiple workbooks?

T

TerryM

Here is my issue, I have a macro that parses text out of a imported file. To
do this I have to Open up one workbook and save it as another (temp.xls)
workbook. The temp file closes or at least appears to however I don't
believe the original workbook closes because I still have a excel.exe in the
Task Manager. Is there any way to rectify this issue, or any code
adjustments that I could make?


Dim wb As Workbook, BeginRow As Long, EndRow As Long
Dim myFile As String
Dim myRange As Range
Workbooks.Open "M:\Forecasting DB\Cin.xls"
BeginRow = [A:A].Find("EJ", after:=[A1]).Row
EndRow = [A:A].Find("EJ", [A65000], , , xlColumns, xlPrevious).Row
ActiveWorkbook.Names.Add "myRange1", Range("A" & BeginRow & ":D" &
EndRow).Address
Range("A" & BeginRow & ":D" & EndRow).Copy
Workbooks.Add 1
Set wb = ActiveWorkbook
ActiveSheet.Paste
[A65000].End(xlUp).Offset(1).Select
Workbooks("CIN.xls").Activate
BeginRow = [A:A].Find("EM", after:=[A1]).Row
EndRow = [A:A].Find("EM", [A65000], , , xlColumns, xlPrevious).Row
ActiveWorkbook.Names.Add "myRange2", Range("A" & BeginRow & ":D" &
EndRow).Address
Range("A" & BeginRow & ":D" & EndRow).Copy
wb.Activate
ActiveSheet.Paste
ActiveWorkbook.SaveAs "M:\ForeCasting DB\temp.xls"
ActiveWorkbook.Close
 
R

royUK

Try adding


Code:
--------------------
wb.Close
--------------------
at the end

You will still have Excel open though

Code:
--------------------

'close Excel
Application.Quit
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit my 'web site
' (http://www.excel-it.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top