标题: 请教:关于导出excel文件工作表名称。 [打印本页] 作者: kennylee 时间: 2011-4-22 10:19 标题: 请教:关于导出excel文件工作表名称。 正常导出excel文件名称=工作表名称,如何在程序确定工作表名称。谢谢!作者: kangking 时间: 2011-4-22 11:51
Public Sub ExportToExcel()
'要引用microsoft excel x.x object library
'要引用microsoft activeX data object x.x library
Dim rs As ADODB.Recordset
Dim cn As ADODB.Connection
Dim Ex As Excel.Application '要引用microsoft excel x.x object library
Dim Wk As Excel.Workbook
Dim Sht As Excel.Worksheet
Dim sql As String
sql = "select * from orders"
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set Ex = CreateObject("EXCEL.application")
With Ex
.Visible = False
Set Wk = .Workbooks.Add
Set Sht = .Worksheets(1)
Sht.Name = "我的命名"
Sht.Range("a1").CopyFromRecordset rs
Sht.SaveAs "c:\我的文件.xls"
.Quit
End With
Set rs = Nothing
Set cn = Nothing
End Sub 作者: byy3322 时间: 2011-4-22 17:27
跟着学习一下作者: gdjdyyj 时间: 2013-5-28 07:30
学习了!!!!