我的EXCEL数据怎么读不出来呢
Dim ExcelApp As New Excel.Application<BR> ExcelApp.Workbooks.Open "e:\lhs\cad\book1.xls", , <BR> ExcelApp.Workbooks("e:\lhs\cad\book1.xls").Activate<BR> ExcelApp.wokbooks.Worksheets("Sheet1").Activate<BR> With ExcelApp.Workbook.Worksheets("Sheet1")<BR> Zkbh = .Range("B2")<BR> Bzdw = .Range("B3")<BR> Gcxm = .Range("B4")<BR> End With<BR> <BR> pt(0) = Pt5(0) + 2.8: pt(1) = Pt5(1) + 2.5: pt(2) = 0<BR> Set TextObj = ThisDrawing.ModelSpace.AddText(Zkbh , pt, 10)<BR> TextObj.ScaleFactor = 0.8以上变量均定义,其中Zkbz,Bzdw,Gcxm均定义位STRING型,PT位double型。
请问楼主错在哪里啊? ExcelApp.wokbooks.Worksheets("Sheet1").Activate
这句有问题,工作簿集合由多个工作簿组成,而单个工作簿又是由多个工作表组成,因而Worksheets("Sheet1").Activate之前应是一个工作簿对象。 我把 With ExcelApp.Workbook.Worksheets("Sheet1") 这句
改为With ExcelApp.ActiveWorkbook.Worksheets("Sheet1")还是不行,到底问题出在哪里了?我在程序运行是在任务管理器里也见不到EXCEL运行啊?(根本就没有调用!!),我引用的是 Microsoft Excel 9.0 Objoct Library ,是什么问题存在啊?
请大侠指点迷津吧!!? 我给你改写了一以下,看行不?
Sub Test()<BR> Dim ExcelApp As Object<BR> Dim TextObj As AcadText<BR> Dim sText As AcadTextStyle<BR> Dim pt5(1) As Double<BR> Dim pt(2) As Double<BR> Dim zkbh As String, bzdw As String, gcxm As String<BR> Set sText = ThisDrawing.TextStyles.Add("hz")<BR> sText.SetFont "ËÎÌå", False, False, 1, 1<BR> sText.Width = 1.2<BR> Set ExcelApp = CreateObject("Excel.Application")<BR> ExcelApp.Workbooks.Open "e:\lhs\cad\book1.xls"<BR> Sheets("Sheet1").Select<BR> zkbh = Range("B2").text<BR> bzdw = Range("B3").text<BR> gcxm = Range("B4").text<BR> pt5(0) = 34: pt5(1) = 24<BR> pt(0) = pt5(0) + 2.8: pt(1) = pt5(1) + 2.5: pt(2) = 0<BR> Set TextObj = ThisDrawing.ModelSpace.AddText(zkbh, pt, 10)<BR> pt(0) = pt5(0) + 32.8: pt(1) = pt5(1) + 2.5: pt(2) = 0<BR> Set TextObj = ThisDrawing.ModelSpace.AddText(bzdw, pt, 10)<BR> pt(0) = pt5(0) + 62.8: pt(1) = pt5(1) + 2.5: pt(2) = 0<BR> Set TextObj = ThisDrawing.ModelSpace.AddText(gcxm, pt, 10)<BR>End Sub 太感谢你了!!!
想不到还有这样无私的高手,我昨天买了一大堆书也没解决问题。
被你几行就搞定了,再说句谢谢!!
页:
[1]