网上找到一篇关于将数据从 Visual Basic 传输到 Excel 的方法其中:Set rs = conn.Execute("Orders", , adCmdTable)
这是把所有的表名为“orders” 的内容那出来 请问如果只要取这张表的某几个字段该怎么办?
 内容如下:
'Create a Recordset from all the records in the Orders table
   Dim sNWind As String
   Dim conn As New ADODB.Connection
   Dim rs As ADODB.Recordset
   sNWind = _
      "C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb"
   conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
      sNWind & ";"
   conn.CursorLocation = adUseClient
   Set rs = conn.Execute("Orders", , adCmdTable)
   
   'Create a new workbook in Excel
   Dim oExcel As Object
   Dim oBook As Object
   Dim oSheet As Object
   Set oExcel = CreateObject("Excel.Application")
   Set oBook = oExcel.Workbooks.Add
   Set oSheet = oBook.Worksheets(1)
   
   'Transfer the data to Excel
   oSheet.Range("A1").CopyFromRecordset rs
   
   'Save the Workbook and Quit Excel
   oBook.SaveAs "C:\Book1.xls"
   oExcel.Quit
   
   'Close the connection
   rs.Close
   conn.Close文章连接:http://support.microsoft.com/default.aspx?scid=kb;zh-cn;247412

解决方案 »

  1.   

    Set rs = conn.Execute("Select filedname1, ..., fieldnameN From Orders")
      

  2.   

    谢谢!
    还有一个问题:这样导出的只有数据 没有列名 能否把列名也一起导入excel呢?
      

  3.   

    http://community.csdn.net/Expert/topic/2662/2662002.xml?temp=.4902613看看这个
      

  4.   

    最后一个问题:能不能自己定义导出的列名 比如列名是"name" 那我在导出的excel里,    是否能定义成中文"姓名”
      

  5.   

    自己回答 Set rs = conn.Execute("Select filedname1 as 自定义名称1, ..., fieldnameN as 自定义名称N From Orders")  结贴!