khidigis 发表于 2008-7-23 08:23:00

请问在VBA中如何调用CAD程序打开DWG文件

<p>请问在VBA中如何调用CAD程序打开DWG文件</p><p>ShellExecute 0, "open", dwgfile, vbNullString, vbNullString, vbNormalFocus //运行不通过,提示没有这个函数定义</p><p>Shell "acad.exe " + dwgfile //找不到acad.exe文件</p><p>Shell "c:\program files\autocad2005\acad.exe" + dwgfile&nbsp; //这样可以运行,但是把路径写死了:(</p><p>有个办法:找到acad.exe程序路径,但不知道如何寻找</p>

英雄无敌 发表于 2008-7-23 21:41:00

<p>通过注册表可以找到ACAD.exe的路径,但如果要打开某一个DWG,在VBA中,你不能直接使用thisdrawing.open ,或者ThisDrawing.Application.Documents.Open来打开图吗?</p>

wuyunpeng888 发表于 2008-7-24 23:00:00

<p>你是想用VB还是想用VBA,是Office的VBA还是CAD的VBA?</p><p>Private WithEvents acadApp As AcadApplication<br/>Private WithEvents acadDoc As AcadDocument<br/>Set acadApp = GetObject(, "AutoCAD.Application")<br/>If Err Then<br/>&nbsp; Err.Clear<br/>&nbsp; Set acadApp = CreateObject("AutoCAD.Application")<br/>&nbsp; If Err Then<br/>&nbsp;&nbsp;&nbsp; MsgBox "ErrorNumber:" &amp; Err.Number &amp; vbNewLine &amp; "Source:" &amp; Err.Source &amp; vbNewLine &amp; Err.Description, 16 ' "无法运行AutoCAD2000,请检查是否安装了AutoCAD 2000", 16<br/>&nbsp;&nbsp;&nbsp; Set acadApp = Nothing<br/>&nbsp;&nbsp;&nbsp; End<br/>&nbsp; End If<br/>End If<br/>acadApp.WindowState = acMax<br/>acadApp.Visible = True<br/>Set acadDoc = acadApp.Documents.Add&nbsp;&nbsp;&nbsp; '添加文档<br/>acadDoc.Open "c:\aa.dwg"</p>
页: [1]
查看完整版本: 请问在VBA中如何调用CAD程序打开DWG文件