Ask Your Question

Macro that launches a Google search of the string selected in LibreOffice [closed]

asked 2016-11-05 03:07:50 +0100

Wolfhart gravatar image


About a year ago, I asked for help on concerning a macro that launches a Google search of the string that is currently selected in LibreOffice. A poster called echo8hink was so kind to give me the code for the macro, namely the following:

sub Google_search
    Dim oSelections, oFirstSelection As Object
    Dim sPhrase, sGooglePhrase,sSplitArray(), sSendPhrase As String
    oSelections = ThisComponent.CurrentSelection
    oFirstSelection = oSelections.getByIndex(0 )
    sPhrase = oFirstSelection.String        'assign selected text to string variable
    If sPhrase = "" Then
        MsgBox "Please select text first."
        Exit Sub
        'work on string, replace space with +
        sSplitArray() = split(sPhrase," ")
        sSendPhrase = Join(sSplitArray(),"+")   
        'build Google string
        sGooglePhrase = ""+sSendPhrase+"%22"
        'launch browser, full screen window, with Google string
    End If
end sub

Now, I have had an idea for a little improvement of the macro, but I do not know how to implement it myself because I do not know how to write a macro. Since does not exist any more, I cannot ask for help there, and so I would like to ask for it here.

The idea for the improvement is the following: What the macro currently does is that it takes the string that is selected in LibreOffice and launches the Internet browser to search for the string (which is first wrapped in quotation marks) on Google. (The macro as given above works on Ubuntu with Chromium installed. For other systems or other browsers, the command "chromium-browser" has to be replaced by the command that launches the intended browser on the given system.) The macro is currently intended for cases where the search string consists of several words. (That's why the string is wrapped in quotation marks.) Sometimes, though, I do not want to search for a string that consists of several words, but only for a single word. And I am thinking that, in such cases, it should not be necessary to select the word, but that it should be sufficient to indicate the word by the position of the cursor. In other words, I would like to change the behavior of the macro in the following way: If no text is selected, then the search string should be the word in which (or at the end of which) the cursor is currently located. But if a certain portion of text is selected, the search string should be the selected text.

Can that be done? If so, can someone tell me how the above macro needs to be modified in order to achieve it?

Thanks in advance for your help!


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-09-15 12:58:14.568741

2 Answers

Sort by » oldest newest most voted

answered 2016-11-11 21:45:57 +0100

Sébastien C. gravatar image

updated 2016-11-11 22:07:46 +0100

Hello-hello everybody...

From France, I think that you have an answer here And I do not post any more in this thread because it is not necessary. Just make a link for posterity that will necessarily index this thread as well.



edit flag offensive delete link more

answered 2016-11-05 15:52:25 +0100

floris v gravatar image

Post your question at or scan the macro section there first. Many users there also have experience with LO and will be able to help.

edit flag offensive delete link more


Thanks! I will do that.

Wolfhart gravatar imageWolfhart ( 2016-11-09 19:25:51 +0100 )edit

Question Tools

1 follower


Asked: 2016-11-05 03:07:50 +0100

Seen: 215 times

Last updated: Nov 11 '16