我得到這一行的編譯時錯誤「未定義的用戶定義類型」:編譯器錯誤:用戶定義類型沒有定義
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
的可能的複製[「用戶定義類型未定義」錯誤(http://stackoverflow.com/questions/24261557/user-defined-type-not-defined-error) – 2016-12-29 08:35:33