我用vb做的,delphi我是超级菜鸟(刚学的),大家不介意我把vb的源代码贴出来吗?
问题就出在下面的一个函数,但由于在我的公司所有机器上都没有问题,所以没法跟踪
到底哪一行出错,公司安装的是同一个光盘上的office2000。
根据对方的反应,对方也装了office2000。出错信息是:不可识别的对象类型。但如果
不安装office2000,错误信息应该是:不能创建对象。所以我怀疑是不是两个office2000的
差异造成。
(引用了excel90的对象库)
问题应该出在前面的几行,与后面的代码无关。
Public Sub loadxls(str1)
'读一个excel文件
'str1:excel文件名
Dim i As Long'temp var
Dim lins As Long'temp var
Dim b1 As New excel.Workbook
Dim sheet1 As New Worksheet
Set b1 = excel.Workbooks.Open(apppath & str1)'估计出错的地方
Set sheet1 = b1.Worksheets(1)
Dim name1 As Long '名称所在行号
Dim bh1 As Long'编号所在行号
Dim gn1 As Long'功能所在行号
For i = 1 To sheet1.Rows.count
If sheet1.Cells(i, 1) = name_str Then name1 = i
If sheet1.Cells(i, 1) = bh_str Then bh1 = i
If sheet1.Cells(i, 1) = gn_str Then gn1 = i
If name1 <> 0 And bh1 <> 0 And gn1 <> 0 Then Exit For
Next
name = str1
bh = str1
gn = str1
lins = 0
If lins = 0 Then
If gn1 <> 0 Then
For i = 2 To sheet1.Columns.count
If Trim(sheet1.Cells(gn1, i)) <> "" Then
gn = Trim(sheet1.Cells(gn1, i))
lins = i
Exit For
End If
Next
End If
Else
gn = Trim(sheet1.Cells(gn1, lins))
End If
If Trim(main.Text1.Text) <> "" Then
If UCase(gn) <> UCase(Trim(main.Text1.Text)) Then Exit Sub
End If
If lins = 0 Then
If name1 <> 0 Then
For i = 2 To sheet1.Columns.count
If Trim(sheet1.Cells(name1, i)) <> "" Then
name = Trim(sheet1.Cells(name1, i))
lins = i
Exit For
End If
Next
End If
Else
name = Trim(sheet1.Cells(name1, lins))
End If
If lins = 0 Then
If bh1 <> 0 Then
For i = 2 To sheet1.Columns.count
If Trim(sheet1.Cells(bh1, i)) <> "" Then
bh = Trim(sheet1.Cells(bh1, i))
lins = i
Exit For
End If
Next
End If
Else
bh = Trim(sheet1.Cells(bh1, lins))
End If
b1.Close
Set b1 = Nothing
excel.Workbooks.Close
excel.Application.Quit
main.List1.AddItem name
main.List2.AddItem bh
main.List3.AddItem gn
Form1.List1.AddItem str1
count = count + 1
End Sub