Shortcut to copy file location in LibreOffice Writer

Its a hack when you switch from MS-Office to LibreOffice due to any reason. One thing thats really fascinating to copy the path of current document. I could not find default implementation of it. If it is there please share in comments section.

After exploring the forum.openoffice.org and some other forums, I found following macro that do the job with some limitations:

Goto Tools -> Macros -> Organize Macros -> LibreOffice Basic... In displayed dialog, create a new one and write below code:

Sub CopyFilePath
 dim document   as object
 dim dispatcher as object
 dim oDoc, oVC, Mark, var
 oDoc = ThisComponent
 oVC = oDoc.CurrentController.getViewCursor
 Mark = oDoc.Text.createTextCursorByRange(oVC)
 oVC.collapseToEnd
 var = ThisComponent.getURL()
 oVC.String = var
 document   = ThisComponent.CurrentController.Frame
 dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
 dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
 oVC.String = ""
 oVC.gotoRange(Mark,false) 
End Sub
  1. Save it and assign a key to it by using following steps:
  2. Open Customize dialog by Tool -> Customize 
  3. Select Keyboard tab
  4. Select available key from Shortcut Keys component
  5. Select your macro from Category component under LibreOffice Macros 
  6. Click on Modify button.
Thats done. Now use your shortcut key to copy the file path of current document without any hassle.
PS: Above code is posted by JohnV at forum.openoffice.org.
Do you enjoy this article? please help spread the word. Your views are valuable.
Post your view