运行时出错...complie error: User-defined type not defined 为什么?
Private Sub cmdReadXLS_Click() Set dgData.DataSource = Read_Excel(App.Path & "\" & "test.xls") Set obj = Nothing End SubPublic Function Read_Excel _ (ByVal sFile _ As String) As ADODB.Recordset On Error GoTo fix_err Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset Dim sconn As String rs.CursorLocation = adUseClient rs.CursorType = adOpenKeyset rs.LockType = adLockBatchOptimistic sconn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sFile rs.Open "SELECT * FROM [sheet1$]", sconn Set Read_Excel = rs Set rs = Nothing Exit Function fix_err: Debug.Print Err.Description + " " + _ Err.Source, vbCritical, "Import" Err.Clear End Function
首先要引用库。dim objExcel as new excel.applicationprivate sub form_load() objexcel.workbooks.open "文件名" '弹出工作表的总数。 msgbox objexcel.activeworkbook.sheets.count objexcel.activeworkbook.close false objexcel.quit set objexcel=nothing end sub http://b4018.xici.net(新任版主,欢迎光临。) 提供:VB、VBA、Office二次开发免费技术支持; 承接:各类项目开发,如MIS系统,WEB网站,中小型应用软件等等;CO.:Vansoft Workroom MSN:[email protected] Email:[email protected] [email protected] TEL:025-86685867(范,24H)
dim objExcel as new excel.application 以上这句提示出错... complie error: User-defined type not defined ????????????????????????????????????????????
http://expert.csdn.net/Expert/topic/2871/2871976.xml?temp=.7418177
User-defined type not defined
为什么?
Set dgData.DataSource = Read_Excel(App.Path & "\" & "test.xls")
Set obj = Nothing
End SubPublic Function Read_Excel _
(ByVal sFile _
As String) As ADODB.Recordset On Error GoTo fix_err
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Dim sconn As String rs.CursorLocation = adUseClient
rs.CursorType = adOpenKeyset
rs.LockType = adLockBatchOptimistic sconn = "DRIVER=Microsoft Excel Driver (*.xls);" & "DBQ=" & sFile
rs.Open "SELECT * FROM [sheet1$]", sconn
Set Read_Excel = rs
Set rs = Nothing
Exit Function
fix_err:
Debug.Print Err.Description + " " + _
Err.Source, vbCritical, "Import"
Err.Clear
End Function
objexcel.workbooks.open "文件名"
'弹出工作表的总数。
msgbox objexcel.activeworkbook.sheets.count
objexcel.activeworkbook.close false
objexcel.quit
set objexcel=nothing
end sub
http://b4018.xici.net(新任版主,欢迎光临。)
提供:VB、VBA、Office二次开发免费技术支持;
承接:各类项目开发,如MIS系统,WEB网站,中小型应用软件等等;CO.:Vansoft Workroom
MSN:[email protected]
Email:[email protected]
[email protected]
TEL:025-86685867(范,24H)
以上这句提示出错...
complie error:
User-defined type not defined
????????????????????????????????????????????
Set excel1 = CreateObject("excel.application")
excel1.workbooks.Open "c:\bo.xls"
excel1.Visible = True
excel1.workbooks.Add
excel1.Cells(1, 1).Value = "This is column A, row 1"
可以打开,结果打开一个空的和bo.xls这两个EXCEL文件,而写只能写在空的那个excel上,怎样才能写在bo.xls这个EXCEL上,而不出现空的EXCEL