How can I make every instance of a word, a hyperlink to a file on my computer.

I have managed to do it with one instance of the word, but repeating this be time consuming so I am hoping that the program itself can do it.

I also would like to use the %windir% and %userprofile% system variables in the file.

Here is what I tried:


However this gets replaced (and fails) by Openoffice to look like this:


If I add double quotes, openoffice adds another pair to the path and that also makes windows not find the file.

I have looked in edit > File & Replace but dont see any option to replace all instalces of a word with a hyperlink to a file whilst keeping the word the same.

  • I am unaware of any mechanism in OpenOffice to do this sort of editing, so what I'd do is to save as HTML, then use a good text editor (such as NotePad++) for the global edits. It can then be re-opened in OpenOffice for further editing, or saving in whatever format is required. However, I doubt if OO will handle environment variables, even if prefixed by file://. – AFH Jun 16 '16 at 23:05
  • Are you asking about Writer or Calc? – Jim K Jun 16 '16 at 23:49

First, select the existing link that you created and copy it. Then, run this macro, which will find all occurrences of "TheWordToLink" and paste the link in those places.

Sub PasteHyperlinks
    Dim vDescriptor, vFound, oVC
    Dim document, dispatcher
    oVC = ThisComponent.CurrentController.ViewCursor
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    vDescriptor = ThisComponent.createSearchDescriptor()
    With vDescriptor
        .SearchString = "TheWordToLink"
        .SearchWords = True
        .SearchCaseSensitive = False
    End With
    vFound = ThisComponent.findFirst(vDescriptor)
    Do While Not IsNull(vFound)
        oVC.gotoRange(vFound, False)
        dispatcher.executeDispatch(document, ".uno:Paste", "", 0, Array())
        vFound = ThisComponent.findNext( vFound.End, vDescriptor)
End Sub

Search and replace code was taken from section 7.14 of Andrew Pitonyak's macro document.

As far as environment variables, that requires a more difficult solution. That is, call a macro from the link, and then the macro will perform the system call to the file. If you are using Basic:

  1. See https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=53609 for how make a hyperlink call a macro.
  2. See Creating automatic links in OpenOffice for code that can find and create the hyperlinks.
  3. See https://forum.openoffice.org/en/forum/viewtopic.php?f=29&t=25047 for a macro that uses an environment variable in a path.
  4. See https://forum.openoffice.org/en/forum/viewtopic.php?f=44&t=7918 for system calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.