VBA调试:Step Into导致整个程序运行

时间:2015-06-11 19:50:11

标签: excel vba excel-vba

我遇到一个问题,在查看我的VBA代码时,我会按下F8到“Step Into”下一行。经过大约8个步骤,当我“踏入”行:设置wb = Workbooks.Open(fileopen)时,它会启动并运行整个程序。我做错了什么?

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

非常感谢。

1 个答案:

答案 0 :(得分:1)

代码行,

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

...告诉我你正在打开一个启用宏的工作簿。此工作簿将具有在打开时启动的事件宏和/或子过程。这将释放调试会话,其余代码将继续运行。