怎么用了这个宏后,就打不开"坐标"这个excel表格了
<p>'调用这个宏后,就打不开"坐标"这个excel表格了,这是怎么回事,请高手指点一下</p><p>Private Sub draw()<br/> Dim xlsApp As Excel.Application<br/> Dim eworkbook As Workbook<br/> Dim eworksheet As Worksheet<br/> Dim cir(0 To 1) As AcadEntity<br/> Dim b(0 To 2) As Double, g(0 To 2) As Double<br/> Dim c As Double<br/> Dim x As Acad3DSolid<br/> Dim d As Double<br/> Dim e As Double<br/> Dim f As Double<br/> Dim re As Variant<br/> Dim height(0 To 1) As Double<br/> <br/> e = 0<br/> Set xlsApp = New Excel.Application<br/> Set eworkbook = xlsApp.Workbooks.Open("F:\国道112\坐标.xls")<br/> Set eworksheet = eworkbook.Sheets("8标的桥位坐标表")<br/> <br/> For i = 4 To 118<br/> <br/> With eworksheet<br/> <br/> b(0) = .Cells(i, 4)<br/> b(1) = .Cells(i, 5)<br/> b(2) = .Cells(i, 6)<br/> c = .Cells(i, 7)<br/> height(0) = .Cells(i, 8)<br/> g(0) = .Cells(i + 1, 4)<br/> g(1) = .Cells(i + 1, 5)<br/> g(2) = .Cells(i + 1, 6)<br/> f = .Cells(i + 1, 7)<br/> height(1) = .Cells(i + 1, 8)<br/> <br/> End With<br/> <br/> Set cir(0) = ThisDrawing.ModelSpace.addcircle(b, c)<br/> Set cir(1) = ThisDrawing.ModelSpace.addcircle(g, f)<br/> <br/> re = ThisDrawing.ModelSpace.AddRegion(cir)<br/> <br/> <br/> <br/> Set x = ThisDrawing.ModelSpace.AddExtrudedSolid(re(0), -height(0), e) '此中的re(0),即acadregion必须为一个域,而不是一个数组。<br/> Set x = ThisDrawing.ModelSpace.AddExtrudedSolid(re(1), -height(1), e)<br/> <br/> i = i + 2<br/> <br/> Next i<br/> <br/> ZoomAll<br/> eworkbook.Close<br/> xlsApp.Quit<br/> <br/> 'eworkbook.Save<br/> Set xlsApp = Nothing<br/> Set eworkbook = Nothing<br/> Set eworksheet = Nothing<br/> <br/> End Sub<br/></p> 本帖最后由 作者 于 2007-5-15 18:57:56 编辑 <br /><br /> <p>标准连接excel方法如下:</p><p>on error resume next</p><p>Set xlsApp =CreateObject(,"excel.Application")</p><p>if err then</p><p> err.Clear</p><p> Set xlsApp =GetObject(,"excel.Application")</p><p> if err then </p><p> msgbox "请先安装excel"</p><p> exit sub</p><p> end if </p><p>end if</p><p> </p> <p>不好意思,我不太懂这个,这一段程序应该放在什么位置?</p><p>我放在了声明后面,出错提示:参数不可选</p><p>Private Sub draw()<br/> '引用 Microsoft Excel 11.0 Object Library<br/> Dim xlsApp As Excel.Application<br/> Dim eworkbook As Workbook<br/> Dim eworksheet As Worksheet<br/> Dim cir(0 To 1) As AcadEntity<br/> Dim b(0 To 2) As Double, g(0 To 2) As Double<br/> Dim c As Double<br/> Dim x As Acad3DSolid<br/> Dim d As Double<br/> Dim e As Double<br/> Dim f As Double<br/> Dim re As Variant<br/> Dim height(0 To 1) As Double<br/> <br/> On Error Resume Next</p><p> Set xlsApp = CreateObject(, "excel.Application")</p><p> If Err Then</p><p> Err.Clear</p><p> Set xlsApp = GetObject(, "excel.Application")</p><p> If Err Then</p><p> MsgBox "请先安装excel"</p><p> Exit Sub</p><p> End If</p><p> End If<br/> <br/> e = 0<br/> <br/> 'Set xlsApp = New Excel.Application<br/> Set eworkbook = xlsApp.Workbooks.Open("F:\国道112\坐标.xls")<br/> Set eworksheet = eworkbook.Sheets("8标的桥位坐标表")<br/> <br/> For i = 4 To 118<br/> <br/> With eworksheet<br/> <br/> b(0) = .Cells(i, 4)<br/> b(1) = .Cells(i, 5)<br/> b(2) = .Cells(i, 6)<br/> c = .Cells(i, 7)<br/> height(0) = .Cells(i, 8)<br/> g(0) = .Cells(i + 1, 4)<br/> g(1) = .Cells(i + 1, 5)<br/> g(2) = .Cells(i + 1, 6)<br/> f = .Cells(i + 1, 7)<br/> height(1) = .Cells(i + 1, 8)<br/> <br/> End With<br/> <br/> Set cir(0) = ThisDrawing.ModelSpace.addcircle(b, c)<br/> Set cir(1) = ThisDrawing.ModelSpace.addcircle(g, f)<br/> <br/> re = ThisDrawing.ModelSpace.AddRegion(cir)<br/> <br/> <br/> <br/> Set x = ThisDrawing.ModelSpace.AddExtrudedSolid(re(0), -height(0), e) '此中的re(0),即acadregion必须为一个域,而不是一个数组。<br/> Set x = ThisDrawing.ModelSpace.AddExtrudedSolid(re(1), -height(1), e)<br/> <br/> i = i + 2<br/> <br/> Next i<br/> <br/> ZoomAll<br/> eworkbook.Close<br/> xlsApp.Quit<br/> <br/> 'eworkbook.Save<br/> Set xlsApp = Nothing<br/> Set eworkbook = Nothing<br/> Set eworksheet = Nothing<br/> <br/> End Sub</p><p>再请指教一下,谢谢了!<br/></p><p></p> 并且这按以前的做最以后还有一个问题就是会出现图形退化,请高手指点一下,这是怎么回事,程序如何更改一下呢?
页:
[1]