Link to home
Start Free TrialLog in
Avatar of Patricia Brenes
Patricia Brenes

asked on

Modify code to open in GC

Hi. Could someone help me modify this macro to open in Google Chrome instead of IE?

Sub Dictionaries()
' Look at different dictionaries
     Dim theTerm As String ' Term to look up in dictionary
     Dim strURL As String ' The URL to open in Explorer
     Dim obj As Object ' Explorer
     Dim arrSites(3)
   
    ' If nothing is selected
    If Selection.Type = wdSelectionIP Then
    ' Select the term where the cursor is located
    theTerm = Selection.Words(1).Text
    Else
    ' Use the current selection
    theTerm = Selection.Text
    End If
   
    theTerm = Replace(theTerm, vbCr, "")  ' Remove any soft returns in the phrase that you have highlighted
    theTerm = Replace(theTerm, vbLf, "")  ' Remove paragraph breaks in the phrase that you have highlighted
    theTerm = Trim(theTerm) ' Remove any spaces
   
    arrSites(0) = "https://cms.unov.org/UNTERM//search?urlQuery=" + theTerm
    arrSites(1) = "http://iate.europa.eu/SearchByQueryLoad.do?method=load" + theTerm
    arrSites(2) = "http://www.btb.termiumplus.gc.ca/tpv2alpha/alpha-fra.html?lang=fra&i=1&srchtxt=" + theTerm
    arrSites(3) = "https://www.linguee.com/english-spanish/search?source=auto&query=" + theTerm + "&title=21st"
    Set objIE = CreateObject("InternetExplorer.Application")
    For i = 0 To 3 Step 1
        strURL = arrSites(i)
        If i = 0 Then
            objIE.Navigate strURL
        Else
            objIE.Navigate2 strURL, 2048
        End If
     Next i
     objIE.Visible = True
     Set objIE = Nothing
End Sub
Avatar of abbas abdulla
abbas abdulla
Flag of Bahrain image

Hi Patricia,
Check this code
Sub Dictionaries()
' Look at different dictionaries
     Dim theTerm As String ' Term to look up in dictionary
     Dim strURL As String ' The URL to open in Explorer
     'Dim obj As Object ' Explorer
     Dim arrSites(3)
   
    ' If nothing is selected
    If Selection.Type = wdSelectionIP Then
    ' Select the term where the cursor is located
    theTerm = Selection.Words(1).Text
    Else
    ' Use the current selection
    theTerm = Selection.Text
    End If
    
    theTerm = Replace(theTerm, vbCr, "")  ' Remove any soft returns in the phrase that you have highlighted
    theTerm = Replace(theTerm, vbLf, "")  ' Remove paragraph breaks in the phrase that you have highlighted
    theTerm = Trim(theTerm) ' Remove any spaces
    
    arrSites(0) = "https://cms.unov.org/UNTERM//search?urlQuery=" + theTerm
    arrSites(1) = "http://iate.europa.eu/SearchByQueryLoad.do?method=load" + theTerm
    arrSites(2) = "http://www.btb.termiumplus.gc.ca/tpv2alpha/alpha-fra.html?lang=fra&i=1&srchtxt=" + theTerm
    arrSites(3) = "https://www.linguee.com/english-spanish/search?source=auto&query=" + theTerm + "&title=21st"
    'Set objIE = CreateObject("InternetExplorer.Application")
    For i = 0 To 3 Step 1
        strURL = arrSites(i)
        If i = 0 Then
            'objIE.Navigate strURL
GoogleChromeExeLocation = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" 'Change this to be the Location of Chrome.exe in your PC
Shell (GoogleChromeExeLocation & " -url " & strURL)

        Else
            'objIE.Navigate2 strURL, 2048
            Shell (ChromeLocation & " -url " & strURL)
            
        End If
     Next i
     'objIE.Visible = True
    ' Set objIE = Nothing
End Sub

Open in new window

Avatar of Pam Ross
Pam Ross

Thanks for taking the time to do this. Really appreciated. It worked!
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.