AutoCAD VBA打开文件对话框

利用vlax的com对象函数

'@var = FileOpenDlg("打开文件:", "D:\", "xls")
'get file dialog use VL.Application
'title@ 字符串,指定对话框的标签。
'Default 要使用的缺省文件名;可为空字符串 ("")。
'ext 缺省的文件扩展名。如果 ext 为空字符串 (""),则缺省值为 *(所有文件类型)。如果该参数中包含 dwg 文件类型,则 getfiled 函数在对话框中显示预览图像框。
Public Function FileOpenDlg(ByVal title As String, Optional ByVal defualPath As String = "", Optional ByVal extStr As String = "") As String
Dim VL As Object, VLF As Object, rtn As String
'根据AutoCAD的版本判断使用的库类型
If VBA.Left(Application.Version, 2) = "15" Then
Set VL = Application.GetInterfaceObject("VL.Application.1")
Else
Set VL = Application.GetInterfaceObject("VL.Application.16")
End If
Set VLF = VL.ActiveDocument.Functions.Item("GetFiled")
rtn = VLF.funcall(title, defualPath, extStr, 8)
Set VLF = Nothing: Set VL = Nothing
FileOpenDlg = rtn
End Function
Public Sub test()
MsgBox FileOpenDlg("打开文件:", "D:\", "dwg")
End Sub

效果

 

posted @   南胜NanSheng  阅读(1415)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示