We help IT Professionals succeed at work.

Single key shortcut for stepping over

381 Views
Last Modified: 2018-12-09
Hi Experts,
Is there a way to use a single keyboard key to perform the following?
Shift-F8      Step over the line by running the procedure on the current line without going into it and stepping through each line
Thanks
Comment
Watch Question

Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Do you want to do this while debugging?
CERTIFIED EXPERT

Author

Commented:
hi,
yes.
Thanks,
Ben
NorieAnalyst Assistant
CERTIFIED EXPERT

Commented:
As far as I know there is no single key shortcut for that but what you could is set a breakpoint on the next line of code and then press F5.
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
In VB6 which is very similar to VBA the shortcut for stepping through was F8 (without Shift). If however you are using a Windows VM like Parallels on a Mac like i am, you may have to use Shift+F8.  You might however be able to set up a Windows shortcut for what you want to do. See my article on debugging for more information.
CERTIFIED EXPERT

Author

Commented:
Hi,
you could is set a breakpoint on the next line of code and then press F5.
I've constantly been debugging lot of code and not interested in stepping thru all the sub functions that are being called by the function I'm looking at, would either have to hold down the shift key all the time while pressing f8 key or perhaps find a way to have windows know that a certain key should be considered same as pressing shift+f8, that could be only while debugging or would not mind if this will be the behavior at all times...
You might however be able to set up a Windows shortcut for what you want to do
Where do you explain this in the article?

Thanks,
Ben
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I'm sorry that I gave the impression that my article talked about creating shortcuts; it doesn't. In any case I don't know what version of Windows you are using but maybe this article which describes how to do it Windows 10 will help you.
CERTIFIED EXPERT

Author

Commented:
Hi,
I'm using Windows 7,
Saw this on google, no idea what is it talking about...
If you want take it even further, create keyboard shortcuts for quick access to Windows 7 settings. Step 1: Right-click on one of the shortcut icons you just created and select "Properties." Step 2: In the "Shortcut key:" field, type a key combination to use as a keyboard shortcut.
Thanks,
Ben
NorieAnalyst Assistant
CERTIFIED EXPERT

Commented:
Ben

When you use F5 code execution will continue, without any stepping, until the next breakpoint.
CERTIFIED EXPERT

Author

Commented:
Hi Norie,

I do want be stepping thru all lines belonging to the function I am looking at, just want avoid entering sub functions, see foe example
    i = UnZip(sDownloadFolder & sLastFile, sDestinationFolder, False)
    
    If i = 0 Then
        sDestinationFolder = "C:\Application\"
        
        If Dir(sDestinationFolder & NewestFile(sDestinationFolder, "*." & sExt)) <> "" Then
            If Dir(sDestinationFolder & "Tables." & sExt) <> "" Then
                Kill sDestinationFolder & "Tables." & sExt
            End If
            Name sDestinationFolder & NewestFile(sDestinationFolder, "*." & sExt) As sDestinationFolder & "Tables." & sExt
        End If
    End If

Open in new window

I want step into all those lines, however Unzip and NewestFile which are other functions I dont step into, and prefer not having to use two keys all the time (Shift+F8).

Most of the times I end up entering unintentionally those functions, then have to use other key combinations for stepping out...

Thanks,
Ben
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You can use conditional compilation as described in this article of mine to do what you want. The article is written for VB6 but using the technique for VBA is very similar. Basically you go to Visual Basic, right-click on the VBA Project in the 'Project - VBAProject' window, select 'Project Properties' and enter something like what is shown here in the 'Conditional Compilation Arguments:' box.
2018-12-04_12-20-47.pngAs long as Testing (or whatever you call it) is 1, then the following code will bypass the calling of SomeSub.
Sub test()
#If Testing Then
    ' Don't do anything
#Else
    SomeSub
#End If
End Sub
Sub SomeSub()
    MsgBox "hello"
End Sub

Open in new window


In your case that code could be simplified to this
Sub test()
#If Not Testing Then
    SomeSub
#End If
End Sub

Open in new window

I've attached a small sample project.
29128192.xlsm
CERTIFIED EXPERT

Author

Commented:
Hi Martin,
then the following code will bypass the calling of SomeSub.
Just to clarify, I'm not looking to bypass the executing those sub functions, just to bypass stepping thru the code line by line, exactly what shift+f8 does.
And this is from your first article above...
Step Over is similar to Step Into except that as its name implies it will step over or skip the current line. Note that it doesn't skip the execution of the line, only the stepping through. In other words if the current line is a call to a long Sub that you don't really care about, stepping over will execute the call and then pause at the line following the call.
Thanks,
Ben
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
The only thing that I can suggest is that if you find yourself in one of the subs that you don't want to step through, click the Debug menu's 'Step Out' button.

2018-12-04_14-16-19.png
NorieAnalyst Assistant
CERTIFIED EXPERT

Commented:
Have you tried setting breakpoints and using F5?

For example in the code you posted you could put breakpoints on line 1 and line 3.

You could then step through the code until you reach line 1 and then press F5 to skip to line 3.
CERTIFIED EXPERT

Author

Commented:
Hi experts,

Have you tried setting breakpoints and using F5?
Yes, I use that occasionally when only want to start debugging from a certain point.
For example in the code you posted you could put breakpoints on line 1 and line 3.
Well normally I'm looking at much larger code, would not be practical to look thru the entire code to find where there is a function called and set there a breakpoint...
click the Debug menu's 'Step Out' button.
As mentioned, this is what I'm currently doing...

I would really prefer the creating shortcut approach that Martin mentioned above, wondering if its doable in windows 7.
 

Thanks,
Ben
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Assuming you can create a shortcut in Win7, what would it emulate? If it's Shit+F8 and you assign it to, say, F9, how would that prevent you from wandering into the subs you don't want to step through? I think you're asking for something to step through code line by line but intelligent enough to step over certain subs and that's not possible.
NorieAnalyst Assistant
CERTIFIED EXPERT

Commented:
Ben

You only occasionally use breakpoints?

If you used breakpoints a bit more, along with F5, then you should be able to skip over code you don't want to step through easily.

As for searching through code for function calls, why not put a breakpoint on the function itself?
CERTIFIED EXPERT

Author

Commented:
If it's Shit+F8 and you assign it to, say, F9, how would that prevent you from wandering into the subs you don't want to step through?
No, I just need something to simulate the exact same behavior as shift+f8, F9 is fine.
Can you provide instructions for accomplishing that?
Thanks,
Ben
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
So you want to F8, F8, F8,...F8 until you get to a certain sub and then press F9 and have it step over, right? If so that is exactly what you can do by pressing the Step Over item instead.

Anyhow here's a Win7 article that may help.
CERTIFIED EXPERT

Author

Commented:
why not put a breakpoint on the function itself?
Not getting it.
If I have a function that is 100 lines long and have within a dozen of calls for other functions, do I have to look for them thru the entire function and place a dozen of breakpoints?
what exactly will that accomplish.
Thanks,
Ben
CERTIFIED EXPERT

Author

Commented:
So you want to F8, F8, F8,...F8 until you get to a certain sub and then press F9 and have it step over, right?
Not either, I just want to use f9 all the time...no switching keys and no using two keys, very simple...
Thanks,
Ben
CERTIFIED EXPERT

Author

Commented:
@Martin,
That link explains how to create a shortcut to particular application. see below
Right-click the desktop shortcut of the application, then click Properties > Shortcuts.
Thanks,
Ben
Martin LissProtect yourself and your loved ones. Stay home for the holidays.
CERTIFIED EXPERT
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Not either, I just want to use f9 all the time...no switching keys and no using two keys
That's not possible.
CERTIFIED EXPERT

Author

Commented:
That's not possible.
So you're saying its not possible to have F9 behave like Shift+F8?
Thanks,
Ben
CERTIFIED EXPERT

Author

Commented:
Just to clarify, currently if I use Shift+F8 all the time while debugging, it does what I want.
My goal here is to avoid constantly having to use a combination of two keys.
Thanks,
Ben
CERTIFIED EXPERT

Author

Commented:
Actually I saw the following on the web
Step 2: Start the Keyboard wizard, and change the assignments
Open the Keyboard item in Control Panel. ...
On the Key Settings tab, select the key that you want to change.
To change the command or the program assignment, click Configure. ...
Select the appropriate options, and then follow the instructions
This looks like something we are trying to accomplish.
The problem is that there is no settings tab under my keyboard item...only tabs I see are speed and hardware-:(
Thanks,
Ben
"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
CERTIFIED EXPERT

Author

Commented:
@Qlemo,\
Caps Lock
might
apply to F8 too (making it Shift-F8)
That would have been a good idea, just a pity it does unfortunately not work-:(
Re the other options, would need some helping hands here...-:)
Thanks,
Ben
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
The latter two options need to be checked by yourself. If you use Logitech gear, look into its setup app.
Regarding AutoHotkey I can only tell it exists, but I do not use it myself.
CERTIFIED EXPERT

Author

Commented:
@Qlemo,
I installed AutoHotKey, started looking into, but could not figure out how to do it.
It looks like you need to write a script in order to accomplish that, there is no GUI helping you.
Any idea how to write this command in a script?
See attached what I tried and error I'm getting.
Thanks,
Ben
Untitled.png
CERTIFIED EXPERT

Author

Commented:
Actually the following types F8 when I press F9.
F9::send +F8

Open in new window

How can I change it to refer to shift+f8?
Thanks,
Ben
CERTIFIED EXPERT

Author

Commented:
I got it
F9::send {shift}+{F8}

Open in new window

Thanks,
Ben
CERTIFIED EXPERT

Author

Commented:
Thanks to all participants!!