0
我正在使用以下代碼從Oracle數據庫中提取一些信息。 我已經多次使用這種類型的Oracle連接和SQL腳本,但是,這個特殊的腳本拋出了應用程序定義或對象定義的錯誤。報告在出現錯誤之前填充7625行。Excel VBA - 應用程序定義或對象定義的錯誤
任何想法?
Sub SQL_CDS()
Sheets("CDS Data").Select
Dim SQL As String
Dim orasession As Object
Dim oradatabase As Object
Dim dyprod As Object
Dim Row As Integer
Application.ScreenUpdating = False
Set orasession = CreateObject("OracleInProcServer.XOraSession") 'Create the OraSession Object. (Oracle)
Set oradatabase = orasession.DbOpenDatabase("sid_cnded", "bo_bca_rep/bobcarep01", 0&) 'Create the OraDatabase Object by opening a connection to Oracle.
SQL = SQL & "SELECT selection_no as one, "
SQL = SQL & "selection_status as two, "
SQL = SQL & "onhand_cds as three, "
SQL = SQL & "allocated_cds as four, "
SQL = SQL & "nr_date as five, "
SQL = SQL & "last_8_weeks_shipped as six, "
SQL = SQL & "reorder_weeks_shipped as seven, "
SQL = SQL & "reorder_status_shipped as eight "
SQL = SQL & "FROM RPAT.BBC_CDS"
Set dyprod = oradatabase.CreateDynaset(SQL, 0&)
Sheets("CDS Data").Select
Row = 2
If Not dyprod.EOF And Not dyprod.bof Then
dyprod.movefirst
Do Until dyprod.EOF
Sheets("CDS Data").Cells(Row, 1).Select
ActiveCell.Value = dyprod.Fields("one").Value
Sheets("CDS Data").Cells(Row, 2).Select
ActiveCell.Value = dyprod.Fields("two").Value
Sheets("CDS Data").Cells(Row, 3).Select
ActiveCell.Value = dyprod.Fields("three").Value
Sheets("CDS Data").Cells(Row, 4).Select
ActiveCell.Value = dyprod.Fields("four").Value
Sheets("CDS Data").Cells(Row, 5).Select
ActiveCell.Value = dyprod.Fields("five").Value
Sheets("CDS Data").Cells(Row, 6).Select
ActiveCell.Value = dyprod.Fields("six").Value
Sheets("CDS Data").Cells(Row, 7).Select
ActiveCell.Value = dyprod.Fields("seven").Value
Sheets("CDS Data").Cells(Row, 8).Select
ActiveCell.Value = dyprod.Fields("eight").Value
dyprod.movenext
Row = Row + 1
Loop
End If
Range("A2").Select
End Sub
感謝SMORF
確實錯誤發生哪條線?爲什麼使用ActiveCell?爲什麼不簡單地把價值? – PaulFrancis
錯誤發生在'ActiveCell.Value = dyprod.Fields(「五」)行'...我一直使用ActiveCell ...以前沒有問題? – SMORF
如果你在VBE立即窗格中執行'?ActiveCell.Value',你會得到一個錯誤嗎?怎麼樣??dyprod.Fields(「五」)。值? –