Issue
Can I gain access to the "Open File Dialog" (with preview) found only in AutoCAD with VBA?
Solution
You can do this through the communication interface with AutoLISP and AutoCAD. The AutoLISP function, getfiled, behaves as the AutoCAD "Open File Dialog" and allows .DWG files to be previewed.
VBA:
Public Sub OpenDialog()
Dim fileName As String
'Using the SendCommand method, send getfiled AutoLISP expressions to the AutoCAD command line.
'Set the return value to a user-defined system variable USERS1.
ThisDrawing.SendCommand "(setvar " & """users1""" & "(getfiled " & """Select a DWG File""" & """c:/program files/acad2012/""" & """dwg""" & "8)) "
'Use the GetVariable method to retrieve this system variable to store the selected file name
fileName = ThisDrawing.GetVariable("users1")
MsgBox "You have selected " & fileName & "!!!", , "File Message"
End Sub
Public Sub OpenDialog(AcadApp As AcadApplication)
Dim ThisDrawing As AcadDocument
ThisDrawing = AcadApp.ActiveDocument
Dim fileName As String
'Using the SendCommand method, send getfiled
‘AutoLISP expressions to the AutoCAD command
‘line.Set the return value to a user-defined
‘system variable USERS1.
ThisDrawing.SendCommand("(setvar " &
"""users1""" &
"(getfiled " &
"""Select a DWG File""" &
"""c:/program files/acad2012/""" &
"""dwg""" & "8)) ")
'Use the GetVariable method to retrieve this
‘system variable to store selected file name
fileName = ThisDrawing.GetVariable("users1")
MsgBox("You have selected " &
fileName & "!!!", ,
"File Message")
End Sub