如何使用VBA在Excel中添加一个新的工作表? [英] How to add a new sheet in excel using VBA?

查看:867
本文介绍了如何使用VBA在Excel中添加一个新的工作表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的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 

这篇关于如何使用VBA在Excel中添加一个新的工作表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆