excelvbamodulestep-into

Module sub wont't step through alone


I have a module in my program that will run when called from the main program but I can not step through it or run it alone and I can't figure out why. When I press F8 nothing at all seems to happen. I want to be able to monitor the variables as I step through the code.

This is the code from the module:

Sub FileCntSub(ByVal StrPath As String)

Dim FolderPath As String, path As String, count As Integer, countstring As String

FolderPath = StrPath

path = FolderPath & "*.htm"

Filename = Dir(path)

Do While Filename <> ""
   count = count + 1
    Filename = Dir()
Loop

countstring = count
Range("Q8").Value = count
'MsgBox count & " : files found in folder"

End Sub

Any ideas why I can't run this alone?

Thanks


Solution

  • You can't begin stepping through a subroutine that requires arguments, such as:

    Sub foo(bar as String)
        MsgBox bar
    End Sub
    

    Pressing F8 does nothing, because the argument bar has not been passed to the procedure.

    Use a breakpoint within the procedure, i.e., on the first statement to execute. Run the procedure however you normally invoke it (from a command button, event-handler, etc.) and then you can step through from the breakpoint onwards.