求助:这些代码生成DLL,无法调用
<p>VBA代码:</p><p>Dim aa As New 工程1.Class1<br/>Sub ff()<br/>aa.xuexi3<br/>End Sub</p><p>VB代码:</p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Option Explicit</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Public Function addline(ByVal document As AcadDocument, ByVal ptSt As Variant, ByVal ptEn As Variant) As AcadLine</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span style="mso-spacerun: yes;"> Set addline = document.ModelSpace.addline(ptSt, ptEn)</font></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">End Function</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Sub ABC()</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">On error resume next</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim objline As AcadLine</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim acadapp As AcadApplication</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim acaddoc As AcadDocument</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Set acaddoc = acadapp.ActiveDocument</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">pt1(0) = 10: pt1(1) = 10: pt1(2) = 0</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">pt2(0) = 150: pt2(1) = 150: pt2(2) = 0</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span style="mso-spacerun: yes;"> Set objline = acaddoc.ModelSpace.addline(pt1, pt2)</font></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">objline.Update</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">End Sub</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><p><font face="Times New Roman"> </font></p></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Sub xuexi3()</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim acadapp As Object 'AcadApplication '</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim acaddoc As Object</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Set acadapp = GetObject(, "AutoCAD.Application")</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Set acaddoc = acadapp.ActiveDocument</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">acadapp.WindowState = acMax </font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Call ABC</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">End Sub</font></p><p></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">应该把acadapp 、acaddoc 声明为模块级变量</font></p> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"></font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman"><span lang="EN-US"><span lang="EN-US"><font face="Times New Roman">将两句提前</font></span></font></span></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim acadapp As AcadApplication</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">Dim acaddoc As AcadDocument</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><span lang="EN-US"><font face="Times New Roman">不行;改为</font></span></p><span lang="EN-US"><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><span lang="EN-US"><font face="Times New Roman">public acadapp As AcadApplication</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><font face="Times New Roman">public acaddoc As AcadDocument</font></p><p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt;"><span lang="EN-US"><span lang="EN-US"><font face="Times New Roman">也不行.</font></span></span></p></span></span> <p>Option Explicit</p><p>private acadapp As AcadApplication</p><p>Sub ABC()<br/>On error resume next</p><p>Dim doc As AcadDocument<br/>Set doc = acadapp.ActiveDocument</p><p>Dim objline As AcadLine<br/>Dim pt1(0 To 2) As Double, pt2(0 To 2) As Double<br/>pt1(0) = 10: pt1(1) = 10: pt1(2) = 0<br/>pt2(0) = 150: pt2(1) = 150: pt2(2) = 0<br/>Set objline = doc.ModelSpace.addline(pt1, pt2)</p><p>End Sub</p><p>Sub xuexi3()<br/>Set acadapp = GetObject(, "AutoCAD.Application")<br/>acadapp.WindowState = acMax <br/>Call ABC<br/>End Sub</p> 多谢板主,可以实现了,我的邮箱:sjsjgcl@163.com
页:
[1]