When running a google search macro from selected text (code below) in Windows 10 I get the following error:
Type:com.sun.star.system.SystemShellExectutionException
Message: Error executing command
This used to work fine in Windows xp. How could I overcome this?
Kind regards,
Paulo
Code: Select all
Sub GoogleSearch()
Dim oCurs As Object, oShell As Object
Dim searchEngineAddress As String, sPhrase As String, sGooglePhrase As String
searchEngineAddress = "https://www.google.com/#safe=active&q="
sPhrase = thisComponent.currentSelection.getByIndex(0).String ' Assign selected text to string variable
mySelection = thisComponent.currentSelection(0)
If Not mySelection.supportsService("com.sun.star.text.TextRange") Then Exit Sub ' Avoid error if selection is a graphic or any other non-text object
sPhrase = mySelection.String ' Assign selected text to string variable
If sPhrase = "" Then
oCurs = mySelection.text.createTextCursorByRange(thisComponent.currentController.viewCursor)
oCurs.gotoStartOfWord(false) : oCurs.gotoEndOfWord(true)
sGooglePhrase = searchEngineAddress & oCurs.string
Else
sGooglePhrase = searchEngineAddress & "%22" & join(split(sPhrase, " "), "+") & "%22"
End If
oShell = createUNOService("com.sun.star.system.SystemShellExecute")
oShell.execute(sGooglePhrase, "", 1) ' Launch browser, full screen window, with Google string.
End Sub