'Non-Basic Code in VBE Call Stack - What Does it Mean?

I am just now learning about how to use the Call Stack within the VBE. One question I have that I cannot seem to find an answer for is what it means when, as I am stepping through two subroutines, why there are two instances of [<Non-Basic Code>] appearing in my Call Stack.enter image description here

I am not sure if it is relevant, but I have included my two subroutines I am stepping through if it helps!

Here are my module-level declared variables (with the exception of Option Explicit):

Option Explicit
Dim fso As Scripting.FileSystemObject
Dim NewFolderPath As String

My first subroutine:

Sub UsingTheScriptingRunTimeLibrary()

Dim OldFolderPath As String

NewFolderPath = Environ("userprofile") & "\Documents\Education\Excel\VBA\Test"                              'where we I am copying TO
OldFolderPath = Environ("userprofile") & "\Documents\Education\Excel\VBA\Excel VBA Introduction - Wise Owl" 'where we are copying FROM

Set fso = New Scripting.FileSystemObject

If fso.FolderExists(OldFolderPath) Then
        
    If Not fso.FolderExists(NewFolderPath) Then
        fso.CreateFolder NewFolderPath
    End If
    
    Call CopyExcelFiles(OldFolderPath) 'since we are sending this as an argument to our CopyExcelFiles sub for its StartFolderPath parameter, we do not need to set it in our next sub
    
End If
Set fso = Nothing
End Sub

Here is my second sub:

Sub CopyExcelFiles(StartFolderPath As String)

Dim Fil As Scripting.File
Dim SubFol As Scripting.Folder
Dim OldFolder As Scripting.Folder

Set OldFolder = fso.GetFolder(StartFolderPath)

For Each Fil In OldFolder.Files
    If Left(fso.GetExtensionName(Fil.Path), 2) = "xl" Then
        Fil.Copy NewFolderPath & "\" & Fil.Name
    End If
Next Fil

For Each SubFol In OldFolder.SubFolders
    Call CopyExcelFiles(SubFol.Path)
Next SubFol

End Sub

Anyways, when I am stepping through my first subroutine, I see my first subroutine listed and one instance of (and this is the literal text) [<Non-Basic Code>]. However, when I begin stepping through my second subroutine, I see two instances of [<Non-Basic Code>] as well as both of my subroutines listed.

Any help on this would be greatly appreciated!



Solution 1:[1]

As freeflow mentions in comment to you, the call stack shows [Non-Basic Code] whenever an external code is called.

Look at this part:

For Each Fil In OldFolder.Files
    ...
Next Fil

You are doing a For Each over the OldFolder.Files; who is the one doing the enumerating? It's not obvious when you program VBA, but if you were writing C, something has to implement the enumerator for the For Each statement to work on. In this case, the Scripting.Files object has implemented a hidden enumerator. Thus, when VBA has a For Each, it's calling the hidden enumerator, and getting a item out of it.

This is not the only way. There are other ways you can see a Non-Basic Code -- a common routine is via event handlers. Say you do a MyWorkbook.Save to save the Excel workbook. That will call events on the workbook such as BeforeSave event and so forth. If you have VBA code in the event handlers, you certainly will see a Non-Basic Code between the calls.

Basically, whenever your code has to pass through some external library to execute the code, the call stack will insert Non-Basic Code to let you know that there's a layer between your VBA code and the previous code that triggered it. There are also cases where your VBA code might be accessed by a non-basic Code entirely so it'll be the first one in the call stack, too.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 this