tcsl9621 发表于 2009-10-22 22:38:00
<p>非常简单。呵……与VB调用EXCEL一样?先添加EXCEL对像。在VBA下定义一个EXCEL对像。再获取或新建一个EXCEL对像。</p><p>调用EXCEL下的WORKBOOKS.sheets.item(1)</p><p>就可以写入对像了。</p>great_kevin 发表于 2010-5-27 11:29:00
<div class="t_msgfont" id="message395456">Sub excell()<br/>Dim x, y As Variant<br/>Dim Excel As Excel.Application<br/>Dim ExcelSheet As Object<br/>Dim ExcelWorkbook As Object<br/>Set ExcelWorkbook = Excel.Workbooks.Open("d:\基础数据.xls") '<br/>Set ExcelWorkbook.Visible = True<br/>Set ExcelSheet = ExcelWorkbook.Worksheets("基础数据") '<br/>ExcelSheet.Activate '<br/>x(0) = 0: x(1) = 0: x(2) = 0<br/>For i = 1 To 50<br/>y(0) = ExcelSheet.cells(i, 1).Value<br/>y(1) = ExcelSheet.cells(i, 2).Value<br/>y(2) = 0<br/>Call ThisDrawing.ModelSpace.AddLine(x(i), y(i))<br/>y = x<br/>Next<br/>End Sub<br/>……………………………………………………………………<br/><font size="4">我的本意是从excel文件(50行、2列)中读取数据,分别作为横纵坐标,Z坐标赋值为0,然后画线<br/>程序不报错,也没反应,不知为何?</font></div><!--Element not supported - Type: 8 Name: #comment--><!--Element not supported - Type: 8 Name: #comment--><font></font><!--Element not supported - Type: 8 Name: #comment-->great_kevin 发表于 2010-5-27 11:32:00
<p>Sub excell()<br/>Dim x, y As Variant<br/>Dim i As Integer<br/>Dim Excel As Excel.Application<br/>Dim ExcelSheet As Object<br/>Dim ExcelWorkbook As Object<br/>On Error Resume Next<br/> Set Excel = GetObject(, "Excel.Application")<br/>If Err <> 0 Then<br/> Set Excel = CreateObject("Excel.Application")<br/>End If<br/>Set ExcelWorkbook = Excel.Workbooks.Open("d:\基础数据.xls")<br/>Set ExcelWorkbook.Visible = True<br/>Set ExcelSheet = ExcelWorkbook.Worksheets("基础数据")<br/>ExcelSheet.Activate<br/>x(0) = 0: x(1) = 0: x(2) = 0<br/>For i = 1 To 50<br/> y(0) = ExcelSheet.cells(i, 1).Value<br/> y(1) = ExcelSheet.cells(i, 2).Value<br/> y(2) = 0<br/> Call ThisDrawing.ModelSpace.AddLine(x, y)<br/> x = y<br/> Next<br/>End Sub</p><p>……………………………………………………………………<br/><font size="4">我的本意是从excel文件(50行、2列)中读取数据,分别作为横纵坐标,Z坐标赋值为0,然后画线<br/>程序不报错,也没反应,不知为何?</font></p><p><font size="4">上面的代码贴错了,这个事最后的!</font><br/></p>xiaowen 发表于 2010-5-27 12:18:00
新手,学习中,感谢分享.xiaowen 发表于 2010-5-30 16:45:00
新手,学习中,感谢分享.短歌行 发表于 2010-6-3 15:03:00
谢谢 学习了lik132 发表于 2010-12-15 17:24:24
非常感谢楼主monkeylzx 发表于 2011-2-25 08:46:32
多谢楼主分享,学习一下为什么任兵 发表于 2012-2-7 21:22:14
楼主辛苦了,很好的教程江湖远人 发表于 2012-2-12 13:50:01
楼主辛苦了,长见识了!