再問EXCEL引用問題,具體請看源程序。以前可以的,這次是怎麼啦。
舍南舍北 2004-05-11 03:04:49 我要讀寫EXCEL 文件
我已經在VB裡引用了Microsoft office 9.0 object library,它的位置在
C:\Program Files\Microsoft Office\Office\EXCEL9.OLB
Option Explicit
Private Sub cmdStart_Click()
Dim SourceXLS As New Excel.Application
'Dim SourceXLS As Excel.Application
'Set SourceXLS = New Excel.Application '???????
Dim Col1() As String
Dim Col2() As String
Dim Col3() As String
Dim Col4() As String
Dim nRows As Long
Dim n As Long
Dim i As Long
Dim j As Long
Dim sFileName As String
If txtRows.Text = "" Then
MsgBox "請輸入源EXCEL文件的行數!", vbExclamation
Exit Sub
Else
nRows = txtRows.Text
End If
CommonDialog1.DialogTitle = "打開EXCEL文件"
CommonDialog1.Filter = "EXCEL文件(*.xls)|*.xls"
CommonDialog1.ShowOpen
sFileName = CommonDialog1.FileName
'SourceXLS.Workbooks.Open App.Path + "\Source.xls" SourceXLS.Workbooks.Open sFileName '提示載入DLL時發生錯誤。
'read data from Excel
For i = 1 To nRows
Col1(i) = SourceXLS.Worksheets(1).Cells(i, 1)
Col2(i) = SourceXLS.Worksheets(1).Cells(i, 2)
Col3(i) = SourceXLS.Worksheets(1).Cells(i, 3)
Col4(i) = SourceXLS.Worksheets(1).Cells(i, 4)
Next i
End Sub