Welcome to MSDN Blogs Sign in | Join | Help

Visual Studio Macro for Live Search

Here is a Visual Studio macro that takes the highlighted text and starts a search of the msdn/msdn2 sites.  It often works better than the built-in help system.  I usually assign it to hot key Alt+F1.

 

'--------------------------------------------------------------------------

'You will need to add a reference to 'System.Web' for HttpUtility.UrlEncode

'--------------------------------------------------------------------------

Public Sub SearchLiveForSelectedText()

    Dim s As String = ActiveWindowSelection().Trim()

    If s.Length > 0 Then

        'If there is a space, then put quotes around the phrase.

        Dim i As Integer

        i = s.IndexOf(" ")

        If i <> -1 Then

            s = """" & s & """"

        End If

 

        'Adding 'header library' to the search string helps focus

        'the search on non-.NET stuff

        Dim ext As String = LCase(Path.GetExtension(ActiveDocument().Name))

        If ext = ".cpp" Or ext = ".inl" Or ext = ".hpp" Or ext = ".cxx" Then

            s = s + " header library "

        End If

 

        DTE.ItemOperations.Navigate("http://www.live.com/?searchonly=true&q=" & _

            Web.HttpUtility.UrlEncode(s) & " (site:msdn2.microsoft.com OR site:msdn.Microsoft.com)")

    End If

End Sub

Published Tuesday, November 07, 2006 8:20 AM by DavidFerguson
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Visual Studio Macro for Live Search

I am replying to your blog because I don't want to clean the kitchen.  This is your sister saying hello from the deep south.  I don't understand any of the code, but it looks impressive!

Thursday, December 07, 2006 8:06 PM by Julia Thomas

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker