macula 发表于 2005-10-28 23:19:00

[VBA]CAD VBA访问Excel出错!

<P>如下程序:</P>
<P>Sub OutEx()&nbsp;</P>
<P>&nbsp; Dim Ex As Excel.Application<BR>&nbsp; Dim ExWorkBook As Workbook<BR>&nbsp; Dim ExSheet As Worksheet<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp; On Error Resume Next<BR>&nbsp; <BR>&nbsp; Set Ex = GetObject(, "Excel.Application")<BR>&nbsp; <BR>&nbsp; If Err &lt;&gt; 0 Then<BR>&nbsp;&nbsp;&nbsp; Err.Clear<BR>&nbsp;&nbsp;&nbsp; Set Ex = CreateObject("Excel.Application")<BR>&nbsp;&nbsp;&nbsp; If Err &lt;&gt; 0 Then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "建立Excel应用出错!"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub<BR>&nbsp;&nbsp;&nbsp; End If<BR>&nbsp; End If<BR>&nbsp;&nbsp;<BR>&nbsp;<FONT color=#ff0000> Set ExWorkBook = Ex.Workbooks.Add&nbsp;&nbsp;<BR>&nbsp; Set ExSheet = ExWorkBook.ActiveSheet&nbsp;&nbsp;<BR>&nbsp; Ex.Visible = True</FONT></P>
<P>End Sub</P>
<P>执行到红色部分,出现以下错误:</P>
<P><FONT color=#0000ff>运行时错误“91”:</FONT></P>
<P><FONT color=#0000ff>对象变量或With块变量未设置</FONT></P>
<P><FONT color=#0000ff></FONT>&nbsp;</P>
<P>程序已经引用了Microsoft Excel 11.0 Object Library</P>
<P>大家帮忙解决以下呀!分析下什么问题?</P>

linyiwq 发表于 2005-11-3 11:12:00

AUTOCAD2002配合Microsoft Excel 8.0 Object Library没有问题!!
页: [1]
查看完整版本: [VBA]CAD VBA访问Excel出错!