error msg:close topmost modal form
error msg:close topmost modal form
(OP)
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??
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??





RE: error msg:close topmost modal form
"Everybody is ignorant, only on different subjects." — Will Rogers
RE: error msg:close topmost modal form
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