Excel宏在Application.GetOpenFilename命令后停止 [英] Excel macro stopping after Application.GetOpenFilename command

查看:506
本文介绍了Excel宏在Application.GetOpenFilename命令后停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下excel(Excel 2010)代码作为更大宏的一部分来选择和打开多个DBF文件:

I am using the following excel (Excel 2010) code as part of a larger macro to select and open multiple DBF files:

Sub Open_multifiles()

Dim multifile As Variant,i As Integer

multifile = Application.GetOpenFilename(FileFilter:=" DBF(* .dbf),* .dbf",MultiSelect:=真)

Sub Open_multifiles()
Dim multifile As Variant, i As Integer
multifile= Application.GetOpenFilename(FileFilter:="DBF (*.dbf), *.dbf", MultiSelect:=True)

If IsArray(multifile) Then

对于i = 1到UBound(var)

Workbooks.Open(multifile(i))

For i = 1 To UBound(var)
Workbooks.Open (multifile(i))

'main macro code to copy data from each open dbf file then closes the open dbf file

Next i

End 如果

'用于处理复制数据的其他代码

'Other code to manipulate copied data

End Sub

WHE在执行宏时,它总是在"IF"处暂停。 GetOpenfilename行之后的语句,其中您已手动按下"Step Out"按钮。调试器工具栏上的命令让宏继续运行。

When executing the macro, it always pauses at the "IF" statement after the GetOpenfilename line wherein you have manually press the "Step Out" command on the debugger toolbar for the macro to continue running.

我尝试添加"DoEvents"。以及"Application.EnableEvents = True"在IF声明之前,这并没有解决问题。尝试使用Excel 2010在不同的计算机上运行相同的代码,并且多选择* .xlsx文件而且遇到了同样的问题。

I tried adding "DoEvents" as well as "Application.EnableEvents = True" before the IF statement and this did not solve the problem. Tried running the same code on a different computer with Excel 2010, and multi-selecting *.xlsx files instead and had the same problem.

可能有一个简单的修复我我失踪了,但已撞墙了。提前感谢任何见解。

Probably there is a simple fix that I am missing but have hit a wall. Thanks in advance for any insights.

推荐答案

Re:文件对话框代码



应该是...... 对于i = LBound(多文件)到UBound(多文件)'不是var



Re: file dialog code

Should be...  For i = LBound(multifile) To UBound(multifile) 'not var

'---

Jim Cone

美国俄勒冈州波特兰市
https:// goo.gl/IUQUN2  (Dropbox)
'---
Jim Cone
Portland, Oregon USA
https://goo.gl/IUQUN2 (Dropbox)


这篇关于Excel宏在Application.GetOpenFilename命令后停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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