这是一个已知的错误,还是我特定的问题(我正在使用Excel 365)。
当我在文件对话框显示调用(选择文件夹或取消)后跳到代码的下一行(F8)时,似乎关闭了单步执行,并将所有代码运行到下一个断点,或者在没有断点的情况下恢复运行代码。
在下面的示例中,我单步执行代码,进入“ fd.show”,然后在我选择文件夹/取消并单击“确定”后,它就运行代码。
Option Explicit
Public Sub Test()
Dim fd As FileDialog
Dim sFile As String
Dim n As Integer
n = 0
sFile = "Work_" & Replace(Date, "/", "") & Replace(Time, ":", "") & ".csv"
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
'*********** SINGLE STEP AFTER SHOW RUNS TO END *******************
If fd.Show = -1 Then
Dim sDir As String
sDir = fd.SelectedItems.Item(1)
If Dir(sFile) = "" Then
n = 1
Else
n = 2
End If
End If
MsgBox CStr(n)
End Sub
F8键在调试时停止工作的解决方法已在contextures上进行了详细说明,here
基本上,您必须向注册表添加一个新项-名称为DisableOrpcDebugging7的DWORD,并将其值更改为1。