Error running google search macro in W10

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
ptbento
Posts: 45
Joined: Fri Jan 18, 2013 9:33 pm

Error running google search macro in W10

Post by ptbento »

Dear all,

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
Last edited by MrProgrammer on Thu Oct 15, 2020 3:44 pm, edited 1 time in total.
Reason: Moved topic from Writer forum to Macros and UNO API
OpenOffice 3.4.1 on Windowx XP
JeJe
Volunteer
Posts: 2783
Joined: Wed Mar 09, 2016 2:40 pm

Re: Error running google search macro in W10

Post by JeJe »

I don't have Windows 10 but can confirm that it runs fine on Windows 8 as well. Have you tried running SystemShellExecute on other commands to see if they work? Could your firewall be stopping you? I wouldn't know but do you need administrator privileges?
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
UnklDonald418
Volunteer
Posts: 1549
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Error running google search macro in W10

Post by UnklDonald418 »

I can confirm that the GoogleSearch() macro works on both Windows 10 Pro and Windows 10 Home using OO 4.1.6 and LO 5.4.7.2
Have you tried it on more than one document?

Try changing the flag value to 0 to see if you get a more helpful error message

Code: Select all

oShell.execute(sGooglePhrase, "", 0)
https://www.openoffice.org/api/docs/com ... Flags.html


Are you still using OO 3.4.1? You might try a more recent version, or maybe LO. You can have both OO and LO installed on the same computer, but I don't recommend running them both at the same time.

Another possible source of the problem could be if you are using Windows Defender for virus protection
[Tutorial] Problems with Windows Defender under Windows 10
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
ptbento
Posts: 45
Joined: Fri Jan 18, 2013 9:33 pm

Re: Error running google search macro in W10

Post by ptbento »

Thank you all very much for your replies.
On changing the flag value to 0 I got the same error message. I will try to check W10 firewall and related protections. I am actually using OO 4.1.17 in W10 , perhaps I will try LO, then.
OpenOffice 3.4.1 on Windowx XP
Post Reply