VBA Step Into (F8) stops midway through sub

GooberTron

Board Regular
Joined
Oct 13, 2012
Messages
218
On Excel 2010 (and 2013) I am having a problem using the Step Into F8 debugging option. After I have selected the folder from the dialog it just seems to stop. Whether I debug from a calling sub or just this sub the same thing happens. Essentially it just stops after the .Show (and after I have used the dialog). Is this a known problem with debugging with dialogs? I found a few related things via Google and on here but nothing concrete. I have added a breakpoint on the next line which seems to be o.k. as a workaround but not ideal.

Code:
Dim FolderPath as String 'module level variable used in other subs

Sub GetFolder()

With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Select folder where sheets reside"
    .AllowMultiSelect = False
    .Show
    
    If .SelectedItems.Count = 0 Then
    Else
        FolderPath = .SelectedItems(1) & "\"
    End If
End With

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
It is going to, and should, "stop" after .Show - until you dismiss the dialog. Could you re-explain what seems screwy about this?
 
Upvote 0
I mean it stops after I have used / dismissed the dialog. Seems to totally exit debug mode unless I put a breakpoint on the If line immediately after the show.
 
Upvote 0
If you place the cursor in GetFolder and press F8 repeatedly, it should stop on:
Code:
If .SelectedItems.Count = 0 Then
...after the dialog is dismissed.

BTW, at least in WIN7 (though I believe in XP as well), you will want to see that the "folder" picked is a real folder. In WIN7, I can pick 'Libraries' and FolderPath is set to 'Libraries\', which I am fairly certain will fall over...
 
Upvote 0
So stepping through it works fine for you? Weird. After dismissing the dialog my sub just runs to completion without any more highlighting / stepping. I see what you mean about trying to enforce a real folder, but the calling code just uses Dir() on the FolderPath so no obvious harm as it just won't find any .xls files I suspect.
 
Upvote 0

Forum statistics

Threads
1,224,883
Messages
6,181,551
Members
453,052
Latest member
ezzat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top