Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88809

Debug jumping lines after file dialog code

$
0
0

Is this a known bug, or something specific to me (I'm using Excel 365).

When I skip to the next line (F8) of code after a file dialog show call (selecting a folder or cancelling) it seems to turn off single stepping and runs all the code to either the next breakpoint or resumes if there is no code.

In the sample below I single step code, it gets to 'fd.show' then as soon as I select a folder/cancel and click ok it just runs the code.

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

Viewing all articles
Browse latest Browse all 88809

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>