Get.OpenFilename数组+“对于每个”或“同时”?

早上好!

我现在只学习了一个星期的VBA …就像从瀑布喝酒一样。 尽pipe研究,我似乎无法把它放在一起。 这个子是打开多个选定的图纸,根据需要进行编辑,直到所有的图纸被编辑。

我正在使用GetOpenFilename来捕获多个文件,然后我想打开并运行我的StandaloneReportEditmacros – 我不确定为什么我不能调用创build的数组,或者我应该研究解决这个问题:

Dim my_FileName As Variant my_FileName = Application.GetOpenFilename( _ filefilter:="Excel Files,*.xl*;*.xm*", _ Title:="Select Excel File to Open", _ MultiSelect:=TRUE) If my_FileName = False Then End Set wb = Workbooks.Open(my_FileName, False, False) Call StandaloneReportEdit 'Sub to very thoroughly edit reports 

在哪里我会使用“For Each”(或者也许Do While),我不能完全弄清楚要引用什么…会是这样的工作吗?

 For Each my_FileName 'Call StandaloneReportEdit here 

或者,我应该使用“Do While”,如下所示:

 Do While my_FileName = True If my_FileName = False Then End Set wb = Workbooks.Open(my_FileName, False, False) Call StandaloneReportEdit Loop 

这个问题可能不会像你们大家所想象的那么彻底,我很抱歉,我想我错过了一些东西,只是被指向正确的方向将不胜感激。 非常感谢您的时间!

For Each是最简单的,但你需要另一个variables从数组中获取名称。 对于Varianttypes的Variant (即使文档提示它 ),对False进行testing也不会很好。 更好地使用IsArray()

 Sub doIt() Dim myFileName As Variant Dim myFileNames As Variant Dim wb As Workbook myFileNames = Application.GetOpenFilename( _ filefilter:="Excel Files,*.xl*;*.xm*", _ Title:="Select Excel File to Open", _ MultiSelect:=True) If Not IsArray(myFileNames) Then Exit Sub For Each myFileName In myFileNames Set wb = Workbooks.Open(myFileName, False, False) StandaloneReportEdit() 'Sub to very thoroughly edit reports Next End Sub