2013-01-07 145 views
1

因此,我創建了此代碼(可能甚至不必顯示它 - 但以防萬一!),無法對其進行測試,因爲我在第一行獲得「用戶定義類型未定義」。我看到了,我應該設置在工具>選項是灰色的,但引用的 參考....Excel宏錯誤 - 「用戶定義類型未定義」 - 引用灰顯

Sub UploadDistributors() 
Dim cnn As ADODB.Connection 
Dim rs As ADODB.Recordset 
Set cnn = New ADODB.Connection 
Set rs = New ADODB.Recordset 

strConn = "Provider=SQLOLEDB-Removed for security-Network Library=DBMSSOCN" 

cnn.Open strConn 

Dim k 
k = 0 

    For i = 1 To 352 

    sSQL = "INSERT INTO DistributorsNP (CompanyName, address, city, state, zip, phone, tollfree) VALUES (" 

    'CompanyName 
    sSQL = sSQL & Sheet1.Range("B" & i).Value & "," 
    'address 
    sSQL = sSQL & Sheet1.Range("C" & i).Value & "," 
    'city 
    sSQL = sSQL & Sheet1.Range("D" & i).Value & "," 
    'state 
    sSQL = sSQL & Sheet1.Range("E" & i).Value & "," 
    'zip 
    sSQL = sSQL & Sheet1.Range("F" & i).Value & "," 
    'phone 
    sSQL = sSQL & Sheet1.Range("G" & i).Value & "," 
    'tollfree 
    sSQL = sSQL & Sheet1.Range("H" & i).Value & "," 



sSQL = sSQL & ")" 
rs.Open sSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText 

rs.Close 

Next 

End Sub 
+1

as @MattCrum暗指下面。確保你在VBE中不在調試模式。 (按下菜單欄中的藍色方塊)。然後可以使用「工具>參考」進行編輯。 –

回答

2

猜您按下停止在編輯器中不再處於中斷模式......?

+0

你是對的,我按下停止,然後能夠看到參考。現在的問題是,即使我添加了參考「Microsoft Visual Basic for Applications Extensibility 5.3」,我仍然得到錯誤 – tree

+4

嘗試添加Microsoft ActiveX數據對象2.8庫 – MattCrum

+0

這樣做謝謝... – tree

相關問題