如何使用VBA在Excel中添加一个新的工作表?如何使用、工作、VBA、Excel

2023-09-08 11:01:57 作者:落笔画秋枫

我是新来的VBA代码。我想填充一个Excel工作表具有不同的数据。要求是提取数据到同一个Excel张单张纸。我需要使用相同类型的低于code,以保持整个code中的完整性。

I am new to VBA coding. I want to populate an excel sheet with different data. The requirement is to pull data into separate sheets of the same Excel. I need to use the same type of code below to maintain the integrity of the entire code.

outfile = "c:\" & Format(Date, "yyyymmdd") & "activedirectorydata.xls"
DoCmd.OutputTo acOutputQuery, "**MoActiveDirectoryData**", acFormatXLS, outfile, False

我能够从一个视图/查询 MoActiveDirectoryData 数据到一个表。我应该如何去从另一个视图/查询获取数据到不同的片材的同一个Excel?

I am able to get data from a view/query MoActiveDirectoryData into one sheet. How should I go about getting data from another view/query into a different sheet of the same excel?

推荐答案

如果您使用DoCmd.TransferS preadsheet,张会在同一文件中,只要表或查询您要导出创建具有不同名称不是已经存在的表。

If you use DoCmd.TransferSpreadsheet, sheets will be created in the same file as long as the table or query that you are exporting has a different name than the sheets that already exist.

outfile = "c:\" & Format(Date, "yyyymmdd") & "activedirectorydata.xls"
''Sheet is called Query1
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Query1", outfile 
''New sheet called Query2
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8, "Query2", outfile