使用 VBA 循环组合框列表并为每个组合框运行 MS Access 宏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5477143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use VBA to loop through combo box list and run MS Access macro for each
提问by Weasy
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.
目前我有一个带有名称组合框列表的 MS Access 2003 表单。使用此工具的方法:您从下拉列表中选择一个名称,然后单击基于所选名称运行的 MS Access 宏(3 个不同的查询),然后打开一个主 Excel 模板并运行一个 Excel 宏,它将创建 1每个销售人员的个人文件。
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.
我想要做的是:使用 MS Access VBA 代码循环组合框中的名称列表,然后运行现有的 MS Access 宏以单独运行名称列表中的每个查询,然后将每个销售人员数据导出到excel 模板已经格式化或只是一个 Excel 文件,我将格式化。
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.
我不想手动选择每个名称,从下拉列表中总共选择了 300 多个名称,运行所有这些查询需要很长时间。我想使用 VBA 代码遍历表单上组合框中的每个名称,并使用每个名称运行现有的 ms access 宏(一起运行 3 个查询),然后我想让该函数将每个单独的文件导出到 Excel . 最终结果是每个销售人员都有自己的 Excel 文件。
回答by Patrick Honorez
Dim i As Long
with myCombo
For i = 0 To .ListCount
Debug.Print .ItemData(i)
Next i
end with