使用 VBA 循环组合框列表并为每个组合框运行 MS Access 宏
目前我有一个 MS Access 2003 表单,其中包含名称组合框列表。使用此工具的方法:从下拉列表中选择一个名称,然后单击 MS Access 宏,该宏根据所选名称运行(3 个不同的查询),然后打开一个主 Excel 模板并运行一个 Excel 宏,该宏将创建 1每个销售人员的个人档案。
我想做的事情:使用 MS Access VBA 代码循环组合框中的姓名列表,然后运行现有的 MS Access 宏来单独运行姓名列表中的每个查询,然后将每个销售人员数据导出到excel 模板已格式化或只是一个 Excel 文件,我将格式化。
我不想手动选择每个名称,从下拉列表中总共有 300 多个名称,运行所有这些查询需要很长时间。我想使用 VBA 代码循环遍历表单上组合框中的每个名称,并使用每个名称运行现有的 ms access 宏(一起运行 3 个查询),然后我想让该函数将每个单独的文件导出到 Excel 。最终结果是每个销售人员都会有自己的 Excel 文件。
Currently I have an MS Access 2003 form with a combo box list of names. The way to use this tool: You select a name from the drop down and then click the MS Access Macro which runs (3 different queries) based upon name selected and then you open a master Excel Template and run an Excel Macro which will create 1 individual file for each salesperson.
What I am trying to do: Use MS Access VBA code to loop though the list of names in the combo box and then run the existing MS Access Macro to run each query from the list of names indiividually and then export each sales persons data to an excel Template which is already formatted or just to an Excel file and I will format.
I dont want to manually select a each name, a total of over 300 names from the drop down, it takes too long to run all of these queries. I want to use VBA code to loop through each name in the combo box on the form and use each name to run the existing ms access macro (which runs 3 queries together) and then I want to have the function export each individual file to Excel. The end result is that each salesperson will have his own Excel file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然 iDevlop 的答案在技术上是正确的,但它也会在最后给出组合框的 Null 值。因此,如果您只想列出不为空的项目,请使用
Although the answer of iDevlop is technically correct, it would also give the Null value of the combobox at the end. So if you just want the listed items without null, use