导入Excel 数据的问题
我有一段代码:Public Function ExporToExcel(stropen As String)
''*********************************************************
''* 名称:ExporToExcel
''* 功能:导出数据到EXCEL
''* 用法:ExporToExcel(sql查询字符串)
''*********************************************************
Dim Rs_Data As New ADODB.Recordset
Dim Irowcount As Integer
Dim Icolcount As Integer
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim xlQuery As Excel.QueryTable
With Rs_Data
If .State = adStateOpen Then
.Close
End If
.ActiveConnection = ConnNetManDB
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Source = stropen
.Open
End With
With Rs_Data
If .RecordCount < 1 Then
MsgBox ("No Record! ")
Exit Function
End If
' '记录总数
Irowcount = .RecordCount
' '字段总数
Icolcount = .Fields.Count
End With
Set xlApp = CreateObject("Excel.Application ")
Set xlBook = Nothing
Set xlSheet = Nothing
Set xlBook = xlApp.Workbooks().Add
Set xlSheet = xlBook.Worksheets("sheet1 ")
xlApp.Visible = True
........
.......
End Function
当运行到 Set xlApp = CreateObject("Excel.Application ")
这句话时报错,错误提示:
ActiveX component can't create object
请问我该怎样修改程序???谢谢!!!
--------------------编程问答-------------------- 哪位高手帮帮我,在线急等急等!!! --------------------编程问答-------------------- Excel 引用了米?
添加上 试试先 --------------------编程问答-------------------- 需要现在在工程里引用EXCEL对象。
VB菜单-》工程-》引用-》EXCEL 随便找个版本 --------------------编程问答-------------------- 工程》引用》Microsoft Excel 11.0 Object Library
这回再试试看 --------------------编程问答-------------------- 我想是引用错误,我也试过,在OFFICE 2003中写的程序,在OFFICE 2000中不能用. --------------------编程问答-------------------- 引用了EXCEL对象,就不要 Set xlApp=CreateObject( "Excel.Application")
不引用EXCEL对象,改:
Dim xlApp As New Excel.Application
-->为:
Dim xlApp as object
其它EXCEL对象类似
调用对象时Set xlApp=CreateObject( "Excel.Application")
--------------------编程问答-------------------- 没有引用就不行了
补充:VB , 基础类