Copying
Change these four lines:
bk.Close SaveChanges:=False
End If
End If
Unload importeren
End Sub
To:
End If
End If
bk.Close SaveChanges:=False
Unload importeren
End Sub
" wrote:
I would like:
Open a workbook with a macro and check if the sheets "list of houses"
and "database" are in that file. And, if yes, the sheets must be
copied to myfile. In both cases the opened file must be closed (after
checking / copying).
But, If the sheets are not available, the file doesn't close and I
don't understand why.
Any help would be appriciated.
------------
Sub importerendb()
Dim bk As Workbook
Range("rekenvel!E2").Value = Range("rekenvel!b13").Value & "\" &
importeren.databasescombo.Value & ".xls"
Dim bestandsnaam
bestandsnaam = Range("rekenvel!E2").Value
Workbooks.Open Filename:=bestandsnaam, Password:="abc"
For Each n In ActiveWorkbook.Names
n.Delete
Next
Dim sh As Worksheet
On Error Resume Next
Set sh = ActiveWorkbook.Worksheets("list of houses")
If Err < 0 Then
bk.Close SaveChanges:=False
MsgBox "No list of houses found"
Else
Set sh = ActiveWorkbook.Worksheets("database")
If Err < 0 Then
bk.Close SaveChanges:=False
MsgBox "No database found"
Else
Sheets(Array("lijstkerken", "database")).Move Befo=Workbooks( _
"myfile.xls").Sheets(1)
bk.Close SaveChanges:=False
End If
End If
Unload importeren
End Sub
|