Results 1 to 6 of 6

Thread: VBA - Google search string in default browser
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Jul 2015
    Posts
    62
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default VBA - Google search string in default browser

    Can anyone help with this please?

    This VBA project is meant to create a Google search string which opens directly in Google search engine in the users default browser. At the moment the search string is not producing the double speech marks around EACH value (which i want to keep). So if the value entered in the input box is 123456 the search string is: "123456 | 12". I am looking for this: "123456" | "12"

    Code:
    Sub Google_Search_v1()
    
    
    Dim Target As Variant
    Dim LValue1 As String
    Dim MyURL As String
    
    
    MyURL = "https:/google.com/#q="
    
    
        Target = Application.InputBox("Enter Number: ")
        
        If Target = 0 Then Exit Sub
        
        LValue1 = """""" & Target & """" & " | " & """" & Left(Target, 2) & """"""
            
        ActiveWorkbook.FollowHyperlink Address:=MyURL & LValue1
    
    
    End Sub
    Any help is much appreciated.
    Thanks

  2. #2
    Board Regular BiocideJ's Avatar
    Join Date
    Jan 2012
    Location
    Florida, USA
    Posts
    1,733
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA - Google search string in default browser

    I believe the corrected line of code is this:

    Code:
    LValue1 = """" & Target & """ | """ & Left(Target, 2) & """"
    I use Excel 365.
    Notusingindentsincodeislikenotusingspacesinsentences.Youcanmakeitout,butonlywithdifficulty.

  3. #3
    Board Regular
    Join Date
    Jul 2015
    Posts
    62
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA - Google search string in default browser

    Quote Originally Posted by BiocideJ View Post
    I believe the corrected line of code is this:

    Code:
    LValue1 = """" & Target & """ | """ & Left(Target, 2) & """"
    Thanks for your help, but I'm afraid that hasn't produced the desired result. The string produced in Google search engine was: 123456 | 12

    So missing the "......"

  4. #4
    Board Regular BiocideJ's Avatar
    Join Date
    Jan 2012
    Location
    Florida, USA
    Posts
    1,733
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA - Google search string in default browser

    Quote Originally Posted by spidaman View Post
    Thanks for your help, but I'm afraid that hasn't produced the desired result. The string produced in Google search engine was: 123456 | 12

    So missing the "......"
    So it does. I didn't take into account that the web address has an additional level of text parsing so you basically need to double up all of your quotes.
    Also, I noticed that if your Target value has a space that it causes this to also not work. This is the reason I added the Replace(...," ", %20). You may need to add additional replaces if other text characters are truncating the search text.

    Here is the TESTED correct line of code:
    Code:
    LValue1 = Replace("""""" & Target & """"""" | """"""" & Left(Target, 2) & """""", " ", "%20")
    Last edited by BiocideJ; Sep 18th, 2019 at 01:24 PM.
    I use Excel 365.
    Notusingindentsincodeislikenotusingspacesinsentences.Youcanmakeitout,butonlywithdifficulty.

  5. #5
    Board Regular
    Join Date
    Jul 2015
    Posts
    62
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA - Google search string in default browser

    Quote Originally Posted by BiocideJ View Post
    So it does. I didn't take into account that the web address has an additional level of text parsing so you basically need to double up all of your quotes.
    Also, I noticed that if your Target value has a space that it causes this to also not work. This is the reason I added the Replace(...," ", %20). You may need to add additional replaces if other text characters are truncating the search text.

    Here is the TESTED correct line of code:
    Code:
    LValue1 = Replace("""""" & Target & """"""" | """"""" & Left(Target, 2) & """""", " ", "%20")
    BiocideJ thanks very much for posting this solution; it now works perfectly. Your help is much appreciated.

  6. #6
    Board Regular BiocideJ's Avatar
    Join Date
    Jan 2012
    Location
    Florida, USA
    Posts
    1,733
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default Re: VBA - Google search string in default browser

    Not a problem. Thanks for confirming it is working.
    I use Excel 365.
    Notusingindentsincodeislikenotusingspacesinsentences.Youcanmakeitout,butonlywithdifficulty.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •