求助!!!!!运行程序提示类型不匹配,怎么解决?
代码如下:Public Function jiyouguimianxian()
Dim excelApp As Excel.Application
Dim excelSheet As Excel.Worksheet
Dim strFile As String
strFile = ThisDrawing.Application.VBE.ActiveVBProject.fileName
Set excelApp = CreateObject("Excel.Application")
excelApp.Visible = False
excelApp.Workbooks.Open Left$(strFile, Len(strFile) - Len("ex01.dvb")) & "\Excel\demo.xls"
Set excelSheet = excelApp.ActiveWorkbook.Sheets("Sheet1")
Dim verts As New cls2dPointArray
Dim vert(0 To 1) As Double
Dim i As Integer, a As Double, b As Double
For i = 2 To excelSheet..End(xlUp)
a = 910 + (Cells(i, 1).Value - Cells(1, 1).Value) / 10
b = 370 + Cells(i, 3).Value - Cells(2, 3).Value
verts.Append vert
vert(0) = a
vert(1) = b
Next i
Dim mspace As New clsModelSpace
mspace.AddLWPolyline verts.toarray()
End Function
问题出现在a、b处,运行到a的时候就提示类型不匹配,怎么回事?
excel中的数据如下:
Cells属性需要有前缀
改成excelSheet .cells 就行了 geabus 发表于 2011-12-1 12:37 static/image/common/back.gif
Cells属性需要有前缀
改成excelSheet .cells 就行了
没有在这个地方出错,加上excelSheet也不行,还是提示类型不匹配。但是改为a=cells(i,1),b=cells(i,3)就可以运行了,也就是说a和b的关系式中不能参加运算过程。 geabus 发表于 2011-12-1 12:37 static/image/common/back.gif
Cells属性需要有前缀
改成excelSheet .cells 就行了
多谢多谢,我发现问题了,问题出在a的运算式中,cells(i,1)-cells(1,1),cells(1,1)是我的表头,应该是cells(2,1)。
页:
[1]