Close File Problem

Close File Problem

Anonymous
Not applicable
306 Views
5 Replies
Message 1 of 6

Close File Problem

Anonymous
Not applicable
Hi,
Non of the following statements are closing the file(with is already open or
active on my autocad) ,can any one tell me please that how I suppose to fix
it?
Thanks.


'==========================================
Private Sub close_all_Click()
'close all details
Dim filename_(1 To 5) As String
Dim i As Integer
Dim answer As String
Dim docs As AcadDocuments

filename_(1) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A20-ROOF & FLOOR.dwg")
filename_(2) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A30-CONNECTION.dwg")
filename_(3) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A40-FOOTING.dwg")
filename_(4) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A10-GLOBAL.DWG")
filename_(5) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\utility\01_UTIL_1.dwg")

answer = MsgBox(" OPEN ALL DETAILS ?! ", vbYesNo)
If answer = vbYes Then
For i = 1 To 5
'On Error Resume Next
docs = filename_(i).Name
Close docs
ThisDrawing.Application.documents.Close filename_(i)
Next
ThisDrawing.Application.documents.Item(strDoc).Close

End Sub

'==========================================
0 Likes
307 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Please Consider this instead;
Is says Invalid qualifiers as an error.

'========================================
Private Sub close_all_Click()
'close all details
Dim filename_(1 To 5) As String
Dim i As Integer
Dim answer As String
Dim docs As AcadDocuments

filename_(1) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A20-ROOF & FLOOR.dwg")
filename_(2) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A30-CONNECTION.dwg")
filename_(3) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A40-FOOTING.dwg")
filename_(4) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A10-GLOBAL.DWG")
filename_(5) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\utility\01_UTIL_1.dwg")

answer = MsgBox(" CLOSE ALL DETAILS ?! ", vbYesNo)
If answer = vbYes Then
For i = 1 To 5
On Error Resume Next
docs = filename_(i).Name
Close docs
ThisDrawing.Application.documents.Close filename_(i)
ThisDrawing.Application.documents.Item(docs).Close

Next

End Sub
'=================================
0 Likes
Message 3 of 6

GTVic
Advisor
Advisor
Regarding your code:
- there is not End If after the Next statement
- "Close docs" Close is for closing files opened with Open
- filename_(i) is of type string so filename_(i).Name is invalid
- The following statements are how the .Close method should be used (no need for ThisDrawing. in front)

Application.Documents("Drawing2.dwg").Close
Application.Documents.Item("Drawing3.dwg").Close

Here is code that works:

[code]
Private Sub close_all_Click()

Dim res As Integer
Dim Doc As AutoCAD.AcadDocument

For Each Doc In Application.Documents
res = MsgBox("Do you want to close this drawing:" + vbLf + vbLf + Doc.Name, vbYesNoCancel + vbQuestion, "Confirm")
If res = vbCancel Then Exit For
If res = vbYes Then
Doc.Close
End If
Next

End Sub
[/code]
0 Likes
Message 4 of 6

Anonymous
Not applicable
Thanks for reply?
so the following codes must be working? but they won't , What is the best
way that I can take the file name (DRAWING.DWG) out of the that string
(directory C:\ ... )?

Thanks again.

'===============================
Private Sub close_all_Click()
'close all details
Dim filename_(1 To 5) As String
Dim i As Integer
Dim answer As String


filename_(1) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A20-ROOF & FLOOR.dwg")
filename_(2) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A30-CONNECTION.dwg")
filename_(3) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A40-FOOTING.dwg")
filename_(4) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A10-GLOBAL.DWG")
filename_(5) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\utility\01_UTIL_1.dwg")

answer = MsgBox(" CLOSE ALL DETAILS ?! ", vbYesNo)
If answer = vbYes Then
For i = 1 To 5
On Error Resume Next
Application.Documents("filename_(i)").Close
'OR Application.Documents.Item("filename_(i)").Close

Next
End If

End Sub
'========================================
0 Likes
Message 5 of 6

Anonymous
Not applicable
None of the two closing statement will work in your foollowing code:

answer = MsgBox(" CLOSE ALL DETAILS ?! ", vbYesNo)
If answer = vbYes Then
For i = 1 To 5
On Error Resume Next
Application.Documents("filename_(i)").Close
'OR Application.Documents.Item("filename_(i)").Close

Next
End If


filename_(i) is a variable from the string array, but you quote it so it
become a string value.

It should be:

Application.Documents(filename_(i)).Close

Also, if you comment out "On Error Resume Next", you will get error break
right at that line of code.

Useing too many "On Error Resume Next" during developing/debugging prevents
you from finding many obvious bugs.



"A-Design" wrote in message
news:4934018@discussion.autodesk.com...
Thanks for reply?
so the following codes must be working? but they won't , What is the best
way that I can take the file name (DRAWING.DWG) out of the that string
(directory C:\ ... )?

Thanks again.

'===============================
Private Sub close_all_Click()
'close all details
Dim filename_(1 To 5) As String
Dim i As Integer
Dim answer As String


filename_(1) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A20-ROOF & FLOOR.dwg")
filename_(2) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A30-CONNECTION.dwg")
filename_(3) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A40-FOOTING.dwg")
filename_(4) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A10-GLOBAL.DWG")
filename_(5) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\utility\01_UTIL_1.dwg")

answer = MsgBox(" CLOSE ALL DETAILS ?! ", vbYesNo)
If answer = vbYes Then
For i = 1 To 5
On Error Resume Next
Application.Documents("filename_(i)").Close
'OR Application.Documents.Item("filename_(i)").Close

Next
End If

End Sub
'========================================
0 Likes
Message 6 of 6

Anonymous
Not applicable
your are trying to close strings called "filename(i)"? remove
the quotes.

You can pull out the drawing name by using the Split function
with a "\" delimiter and grabing the last value in your array.

"A-Design" wrote in message
news:4934018@discussion.autodesk.com...
Thanks for reply?
so the following codes must be working? but they won't , What is the best
way that I can take the file name (DRAWING.DWG) out of the that string
(directory C:\ ... )?

Thanks again.

'===============================
Private Sub close_all_Click()
'close all details
Dim filename_(1 To 5) As String
Dim i As Integer
Dim answer As String


filename_(1) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A20-ROOF & FLOOR.dwg")
filename_(2) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A30-CONNECTION.dwg")
filename_(3) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A40-FOOTING.dwg")
filename_(4) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\A10-GLOBAL.DWG")
filename_(5) = LCase("C:\Documents and
Settings\afshin.ST-1.000\Desktop\D\utility\01_UTIL_1.dwg")

answer = MsgBox(" CLOSE ALL DETAILS ?! ", vbYesNo)
If answer = vbYes Then
For i = 1 To 5
On Error Resume Next
Application.Documents("filename_(i)").Close
'OR Application.Documents.Item("filename_(i)").Close

Next
End If

End Sub
'========================================
0 Likes