I have written the following codes to open some files,now I need to make another module that can close them , how should I do this? what ever I tried I couldn't make it,can anyone help me with that? Thanks in advance. Afshin. Sub open_all_details() Dim drawingfile As AcadDocument Dim directory(0 To 3) As String Dim i As Integer i = 0 directory(0) = "C:\Documents and Settings\afshin.ST-1.000\Desktop\D\A10-GLOBAL.DWG" directory(1) = "C:\Documents and Settings\afshin.ST-1.000\Desktop\D\A20-ROOF & FLOOR.dwg" directory(2) = "C:\Documents and Settings\afshin.ST-1.000\Desktop\D\A30-CONNECTION.dwg" directory(3) = "C:\Documents and Settings\afshin.ST-1.000\Desktop\D\A40-FOOTING.dwg" For i = 0 To 3 If Dir(directory(i)) <> "" Then Set drawingfile = Application.Documents.Open(directory(i)) Else MsgBox "File " & directory(i) & " does not exist." End If Next End Sub
Have you tried iterating the documents collection? You can check each name to determine if it must be closed. Michel Sub CloseDoc(strDoc As String) Dim objDoc As AcadDocument For Each objDoc In Application.Documents If objDoc.FullName = strDoc Then objDoc.Close Exit Sub End If Next End Sub