vba Excel 宏错误 - “未定义用户定义的类型” - 引用变灰
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14198983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel Macro Error - "User Defined Type Not Defined" - References Grayed out
提问by tree
So I created this code (probably don't even have to show it- but just in case!), have not been able to test it as I get "User defined type not defined" on the first line. I saw that I should set the reference in Tools>References but the option is grayed out....
所以我创建了这段代码(可能甚至不必显示它 - 但以防万一!),因为我在第一行得到“未定义用户定义的类型”而无法对其进行测试。我看到我应该在工具>参考中设置参考,但该选项呈灰色....
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
回答by MattCrum
Guessing you've pressed stop in the editor and are no longer in break mode...?
猜猜你在编辑器中按下了停止键并且不再处于中断模式......?