简体   繁体   English

ms访问导出为ms excel格式

[英]ms access export to ms excel format

I have an access database with 1 table 6 columns ie item, units, quote1, quote2, quote3 and quote4. 我有一个带有1表6列的访问数据库,即项目,单位,quote1,quote2,quote3和quote4。

I would like to have a form where items are type and an excel sheet is produced with the same format but only items typed are printed and exported to excel. 我希望有一个表单,其中键入项目,并以相同的格式生成excel表,但仅打印键入的项目并导出到excel。

The excel sheet has the following format No, Item, Units, SOH, quote1, quote2, quote3, quote4. Excel工作表具有以下格式:No,Item,Units,SOH,quote1,quote2,quote3,quote4。

How do I accomplish this? 我该如何完成?

The approach I used at work is as follows: 我在工作中使用的方法如下:

Build a form with the data fields you would like to export put on it. 用您要导出的数据字段构建表单。

Start a new module and put the following sample code inside. 启动一个新模块,并将以下示例代码放入其中。 My form was called "TableView" 我的表单称为“ TableView”

Sub exportcasetable4()
  DoCmd.OpenForm "TableView", acFormDS
  Forms!tableview.SetFocus
  DoCmd.RunCommand (acCmdSelectAllRecords)
  DoCmd.RunCommand (acCmdCopy)
  Dim objXLOutput As Object
  Dim objWBOutput As Object
  Dim objWSOutput As Object
  Set objXLOutput = CreateObject("Excel.Application")
  objXLOutput.Visible = True
  Set objWBOutput = objXLOutput.Workbooks.Add
  Set objWSOutput = objXLOutput.ActiveWorkbook.ActiveSheet
  objWSOutput.Range("A1").Select
  objWSOutput.PasteSpecial Format:="Unicode Text", Link:=False, DisplayAsIcon _
    :=False
  objWSOutput.Range("A1").Select
  DoCmd.Close acForm, "TableView"
  Set objXLOutput = Nothing
  Set objWBOutput = Nothing
  Set objWSOutput = Nothing
End Sub

You can then call this subroutine and it will dump all the data fields into Excel. 然后,您可以调用此子例程,它将把所有数据字段转储到Excel中。 You may choose to call it from a button. 您可以选择通过按钮调用它。

Hope this help! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM