Thanks OriginalGriff! This is great and really helped me out. :-D
However, for my tastes I like to open the URL in the default browser (currently that's Chrome for me), which allows me to easily open up several tabs from the links or bookmark useful entries.
Also, the original F1 would search the Help based on what word the text cursor was on, whether it was selected or not. I liked the ease of that.
Last, but not least, as I was writing a blog post on this great tip I stated that 95% of the time my search term came up in the first result. Then it hit me. :omg: If I think that what I want will be my first hit, why not just return Google's first result; the equivalent of hitting the older I'm Feeling Lucky button on Google's home page. So, I added a second subroutine that does exactly that. I set the key assignment for
GoogleSearchMSDN_FeelingLucky
to Shift+F1. Now, if I think a term is likely to return what I want in the first hit, like "
msdn ActionResult
" grabs the Microsoft MSDN page for the
ActionResult
class, then I use Shift+F1, otherwise I just use the standard F1 and get all the results.
So, I updated the code with these three features as follows:
Sub GoogleSearchMSDN_FeelingLucky()
GoogleSearchMSDN(True)
End Sub
Sub GoogleSearchMSDN(Optional ByVal feelingLucky As Boolean = False)
Dim url As String
Dim text As String
Dim searchFor As TextSelection = DTE.ActiveDocument.Selection()
If Not searchFor.IsEmpty Then
text = searchFor.Text
Else
Dim currentColumn As Integer = searchFor.ActivePoint.DisplayColumn
searchFor.WordLeft()
searchFor.WordRight(True)
text = Trim(searchFor.Text)
searchFor.MoveToDisplayColumn(0, currentColumn)
End If
url = "http://www.google.com/search?q=MSDN+" + text
If feelingLucky Then
url += "&btnI=745"
End If
System.Diagnostics.Process.Start(url)
End Sub
I hope this helps!