It's designed that way. This code assumes it is was closed and we opened it and should now close it again.
We can check to see if it was open, and leave it open if it was:
Sub ImportData()
' JBeaucaire 8/20/2009
Dim ws As Worksheet, wsNw As Worksheet
Dim wb1 As Workbook, wb2 As Workbook
Dim LR As Long, chk As Boolean
chk = Evaluate("ISREF('[Murphy-Book1.xls]Sheet3'!A1)")
Set wb2 = ThisWorkbook
Sheets.Add
If Not chk Then
Set wb1 = Workbooks.Open("Murphy-Book1.xls")
Else
Set wb1 = Workbooks("Murphy-Book1.xls")
wb1.Activate
End If
Sheets("Sheet3").Activate
Cells.Copy
wb2.Activate
ActiveSheet.Paste
Rows("1:1").Insert Shift:=xlDown
If Not chk Then wb1.Close False
Range("D1") = "Data"
Range("D1").AutoFilter
LR = Range("A" & Rows.Count).End(xlUp).Row
Set wsNw = ActiveSheet
For Each ws In Worksheets
If ws.Name <> wsNw.Name Then
ws.UsedRange.Clear
wsNw.Range("A1").AutoFilter field:=4, Criteria1:=ws.Name
If Range("A" & Rows.Count).End(xlUp).Row > 1 Then _
wsNw.Range("A2:H" & LR).Copy ws.Range("A1")
End If
Next ws
Application.DisplayAlerts = False
wsNw.Delete
Application.DisplayAlerts = True
End Sub
Bookmarks