Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

error msg:close topmost modal form

Status
Not open for further replies.

jrice174

Civil/Environmental
Nov 8, 2004
129
I'm attempting to write a vba program to open all the drawings in a directory. It opens the first drawing fine, but after opening the second drawing it gives me an error message "must close or hide topmost modal form first".

Here is the code:

Public Sub OpenDwgs()
DirName = "K:\_a\A05309\"
DwgNames(1) = "A0530912"
DwgNames(2) = "A0530913"
DwgNames(3) = "A0530914"
For i = 1 To 3
DwgName = DirName & DwgNames(i) & ".dwg"
MsgBox DwgName
Set CurrentDwg = Application.Documents.Open(DwgName)
'(code goes here)
CurrentDwg.Close
Next i
End Sub

Any ideas what the problem is??
 
Replies continue below

Recommended for you

Thanks for the help
This how I got around it....

' In order for this to work the Microsoft Scripting Runntime reference must be added to the project
Dim FileItem As File
Dim SourceFolder As Scripting.Folder
Dim FSO As Scripting.FileSystemObject
Public Sub OpenDwgs()
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(mypath)
r = 0
For Each FileItem In SourceFolder.Files
r = r + 1
Set FSO = New Scripting.FileSystemObject
Set SourceFolder = FSO.GetFolder(mypath)
If Right$(FileItem.Name, 4) = ".dwg" Then
Set CurrentDwg = Application.Documents.Open(mypath & FileItem.Name)
Call DoSomething
ThisDrawing.Close
End If
Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor