最近再写一个小程序,VB 6.0 调用Excel函数的,在运行过程中出现如下错误
以下为部分代码:For dblRow = 1 To myCount
strCol = ""
myString = ""
For dblCol = 1 To 5
strCol = xlsheet.Cells(dblRow, dblCol).Value
Select Case dblCol
Case 1
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 12 - LenB(strCol))
myString = myString & myAnswer & ","
Case 2
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 30 - LenB(strCol))
myString = myString & myAnswer & ","
Case 3
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 17 - LenB(strCol))
myString = myString & myAnswer & ","
Case 4
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 30 - LenB(strCol))
myString = myString & myAnswer & ","
Case 5
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 12 - LenB(strCol))
myString = myString & myAnswer
End Select
Next
dblTotal = dblTotal + 1
tsfile.WriteLine (myString)
以下为部分代码:For dblRow = 1 To myCount
strCol = ""
myString = ""
For dblCol = 1 To 5
strCol = xlsheet.Cells(dblRow, dblCol).Value
Select Case dblCol
Case 1
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 12 - LenB(strCol))
myString = myString & myAnswer & ","
Case 2
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 30 - LenB(strCol))
myString = myString & myAnswer & ","
Case 3
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 17 - LenB(strCol))
myString = myString & myAnswer & ","
Case 4
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 30 - LenB(strCol))
myString = myString & myAnswer & ","
Case 5
Set myRange = xlsheet.Cells(dblRow, dblCol)
myAnswer = Trim(strCol) & xlapp.WorksheetFunction.Rept(" ", 12 - LenB(strCol))
myString = myString & myAnswer
End Select
Next
dblTotal = dblTotal + 1
tsfile.WriteLine (myString)
图片内容:
实时错误‘1004’
不能取得类 WorkSheetFunction 的 Rept属性
String(12 - LenB(strCol), " ")