Are there any macros for OpenOffice that enable certain words to automatically be replaced with hyperlinks?
Every time I type the word "google" in OpenOffice, I want the word to become a hyperlink to http://www.google.com/
Are there any macros for OpenOffice that enable certain words to automatically be replaced with hyperlinks?
Every time I type the word "google" in OpenOffice, I want the word to become a hyperlink to http://www.google.com/
AFAIK you can't let OOo immediately replace a word by a hyperlink (without writing a macro), but you can achieve this by combining AutoReplace and URL recognition:
GoogleWWW
" by "http://www.google.com
" (as text);Format
-> AutoCorrect...
-> Apply
to make OOo replace the link text by a hyperlink.I've proposed "GoogleWWW
" as Text to replace, because if you use simply "google", the replacement will take place a second time when the hyperlink is created, resulting in a link text looking like www.http://www.google.com.com
.
EDIT:
Here's the source of a simple macro to replace arbitrary selected text by a hyperlink (use with care, it's just a "proof of concept" - for example, it doesn't check if the selected text contains spaces, so the resulting link may point to a invalid url):
sub ReplaceByHyperlink
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
dim oSelection, oRange as object
dim strSelectedWord as String
rem ----------------------------------------------------------------------
rem get access to the document and grab first selection
oSelection = ThisComponent.CurrentController.Selection
oRange = oSelection(0)
rem ----------------------------------------------------------------------
rem rudimentary input check (selection available, text selected?)
If Not (HasUnoInterfaces(oRange, "com.sun.star.text.XTextRange")) Then
MsgBox "no text available"
exit sub
End if
strSelectedWord = oRange.getString
If Len(strSelectedWord) < 1 Then
MsgBox "No Text selected"
exit sub
End if
rem ----------------------------------------------------------------------
rem ok, there's some text selected, let's transform it...
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(4) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Hyperlink.Text"
args1(0).Value = strSelectedWord
args1(1).Name = "Hyperlink.URL"
args1(1).Value = "http://www." + LCase(strSelectedWord) + ".com/"
args1(2).Name = "Hyperlink.Target"
args1(2).Value = ""
args1(3).Name = "Hyperlink.Name"
args1(3).Value = strSelectedWord
args1(4).Name = "Hyperlink.Type"
args1(4).Value = 1
dispatcher.executeDispatch(document, ".uno:SetHyperlink", "", 0, args1())
end sub
You can assign this macro to a keyboard shortcut using Tools
-> Customize
-> Keyboard
, to SHIFT+CTRL+G, for example. This, way, you don't need to define a AutoCorrect
rule.