Visual Studio Tab Un-stupidifier Macro
Necessity is the mother of dodgy macros, they say. Here’s one I made to fix the stupid most recently- to last recently-used document tab order of Visual Studio. But before the code, here is my harrowing tale….
I remember doing user interface design courses in my undergrad study, and thinking “I don’t need to pay attention to this - by the time I’m out in the real world UI standards will be firmly in place.”
I remember this today as I try to tab to an open document in Visual Studio.
I can see the tab - it is right in front of me, but ctrl-tab as I might I can not get to it. The active document jumps around from document to document until finally, like a really really frustrating game of roulette, I land on the code page I seek. Seeked. Sake?
By this time I had forgotten why I was even going to the page, and realised that every time I hit ctrl-tab (or ctrl-f6 in VS 2005), I ground my teeth just a little bit more.
Don’t get me wrong, being able to go to the last file you used is pretty handy. It’s just not as handy as being able to scroll through your open documents without having to yell rude words at your co-workers.
If fact, the MRU order is good if you only ever need to access the last file you were working on. Which is unlikely to be the case if you are working on a chunky project with lots of documents open. See my graph for clarification.
So I had a look around for the necessary keyboard short-cut, or registry setting I needed to apply to remove someone’s great idea for changing the way tabs work. I couldn’t find it, so in a fit of angriness, I ended up writing this dodgy macro. It’s probably THE worst way to accomplish the task, but hey - I use a GOTO statement, so it can’t be all bad:
Public Sub TabForward()
Dim i As Integer
Dim activateNext As Boolean = False
For i = 1 To DTE.Windows.Count
If DTE.Windows().Item(i).Kind = "Document" Then
If activateNext Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
If DTE.Windows().Item(i) Is DTE.ActiveWindow Then
activateNext = True
End If
End If
Next
' Was the last window... go back to the first
If activateNext Then
For i = 1 To DTE.Windows.Count
If DTE.Windows().Item(i).Kind = "Document" Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
Next
End If
done:
End Sub
Public Sub TabBackward()
Dim i As Integer
Dim activateNext As Boolean = False
For i = DTE.Windows.Count To 1 Step -1
If DTE.Windows().Item(i).Kind = "Document" Then
If activateNext Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
If DTE.Windows().Item(i) Is DTE.ActiveWindow Then
activateNext = True
End If
End If
Next
' Was the first window... go back to the last
If activateNext Then
For i = DTE.Windows.Count To 1 Step -1
If DTE.Windows().Item(i).Kind = "Document" Then
DTE.Windows().Item(i).Activate()
GoTo done
End If
Next
End If
done:
End Sub
I don’t know if it works in VS2005 - I only have the freebie version.
All that’s left to do then is to map TabForward to ctrl-tab and TabBackward to ctrl-shift-tab. You do this in tools->options->keyboard. I then set the old Window.NextDocumentWindow to ctrl-f6 so if I want to use the MRU order I can.
So far I haven’t wanted to.


“Sought”
-hankI really think it should be “Sorked”.
Also, now that I’m free from the shackles of the MRU tab order, I realise that this post is a bit nastier than it needed to be. Sorry MRU tab order - you do come in handy sometimes. I didn’t mean to get angry.
-Mr. SpeakerIt works! Even under Visual Studio 2005!
I was looking for a beer oclock update for ff2.0 (ok, it’s not too harder to manually fix the version, but something official is way better) and I found this wonderful macro.
You save my sanity :-P
ciao
-sid77Thank you so much!!!
This is really the best post I’ve ever seen online, bar none :) well pr0n doesn’t count.
please put some metatags in so it’s easier to find, maybe “fix visual studio 2005 tab order” ctrl+tab, etc.
thanks again
-AlexWorks for me too in VS2005! Thank you so much!
Now if only someone knows how to disable this amazingly impressively stupid feature of VS2005 which makes a “pop” sound every time I run this macro, as well as displaying a balloon notification…
-RomanI said that too fast. It actually only works in limited circumstances - namely, you must not reorder tabs. If you do, it breaks. Which almost defeats the purpose for me.
Does anyone know how to detect such reordered tabs?
-RomanHmmm… I have only just started using vs2005, and didn’t even know you could re-order the tabs - thanks!
I’ll check it out on Monday when I’m back on my windows box.
(Oh, and there is a way to stop the macro notification… but I forget how I did it!)
-Mr. SpeakerTnank you X infinity
The idiotic tab order AND even stupider tab **DIALOG** gone in one simple pair of macros =)
This has been one of the most irritating points of VS, made worse by the fact that fools _copy_ it (!), and I can’t thank you enough. I didn’t even know this kind of thing was possible with macros.
I came here looking for something to automatically rearrange tab orders on a windows form, but this is better =) And does anyone else notice that all of ms/vs is now just an attempt to recreate Access?
-AndrewThe balloon and popping sound can be disabled using the advice here: http://tinyurl.com/34yznu
In summary, you need to add the following to your registry:
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0]
-Mun“DontShowMacrosBalloon”=dword:00000006
@Roman: You don’t even have to reorder tabs for the script to break. Some combinations of tabbing around and closing files also break the script. DTE.Windows simply isn’t guaranteed to give items to you in the tab bar order.
We need direct programmatic access to the tab bar if we’re to get the behavior we want. Either that, or VS 10 has got to allow it as an option. Tabbed web browsers are simply too widespread these days to cling to old UI paradigms.
-Tabber