本文介绍了编译器错误:未定义用户定义的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这一行得到编译时错误用户定义的类型未定义:
I get the compile-time error "User-defined types not defined" on this line:
Dim cn As ADODB.Connection
可能有什么问题?
代码:
Sub test()
Dim cn As ADODB.Connection
'Not the best way to get the name, just convenient for notes
strFile = Workbooks(1).FullName
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"
Set cn = CreateObject("ADODB.Connection")
'For this to work, you must create a DSN and use the name in place of
'DSNName
'strSQL = "INSERT INTO [ODBC;DSN=DSNName;].NameOfMySQLTable " & "Select AnyField As NameOfMySQLField FROM [Sheet1$];"
strSQL = "SELECT F1 FROM [Sheet1$];"
cn.Execute strSQL
End Sub
推荐答案
我忘了添加Microsoft ActiveX数据对象2.5库的引用:
I had forgotten to add a reference to "Microsoft ActiveX Data Objects 2.5 Library":
工具>参考>检查Microsoft ActiveX数据对象前面的复选框2.5图书馆
Tools > References > Check the checkbox in front of "Microsoft ActiveX Data Objects 2.5 Library"
这篇关于编译器错误:未定义用户定义的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!