VBAdebugging:步入导致整个程序运行

我遇到了一个问题,在查看我的VBA代码时,我将按F8“进入”下一行。 大约8步后,当我“步入”行: 设置wb = Workbooks.Open(文件打开 ,它启动并运行整个程序。 我究竟做错了什么?

Sub NSC_test() ' ' NSC_test Macro ' ' Keyboard Shortcut: Ctrl+u ' Const filepath As String = "H:\DEPT\Supply Management\Shared\No Standard Cost Reports\No Standard Cost Reports FYE 15\" Dim filename As String Dim fileopen As String Dim lastrow As Integer Dim tempcell As Range Dim ws As Worksheet If ActiveWorkbook.Name = "NSC Template.xlsm" Then 'DATE OF PREVIOUS WEEK'S REPORT filename = Format(DateAdd("d", -1, Now()), "mm-dd-yy") 'SET THIS BACK TO -7 filename = "NSC " & filename & ".xlsm" fileopen = filepath & filename 'MsgBox fileopen 'TO CHECK IF THE FILEPATH IS CORRECT Dim wb As Workbook Set wb = Workbooks.Open(fileopen) If wb Is Nothing Then MsgBox "File does not exist": Exit Sub blah blah 

非常感谢。

代码行,

 filename = "NSC " & filename & ".xlsm" 

…向我表明您正在打开一个启用macros的工作簿。 此工作簿将具有在打开时启动的事件macros和/或子过程。 这将释放debugging会话,其余的代码将运行其过程。