Ask Your Question

Attach macro to a file?

asked 2017-03-24 17:12:22 +0100

LibreGuy gravatar image


  1. Is it possible to attach a macro to a Calc file?

  2. Can this macro be assigned to a keyboard shortcut?

What I would like to know is if it is possible to attach a specific macro to a Calc file and assign this to a keyboard shortcut, for example Ctrl + T. Then if someone else opens this file on another computer, he can press Ctrl + T and the macro will be executed.

So 2 things have to happen. The macro must be integrated into the Calc file, and it must also be assigned to a keyboard shortcut.

Can that be done, or is it impossible?

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted

answered 2017-03-24 17:29:41 +0100

Ratslinger gravatar image

updated 2017-03-25 00:37:02 +0100

In addition to @Mike Kaganski answer, you can also attach a macro to a toolbar (new or existing) or even a menu for the specific document thus eliminating the need for keyboard bindings.


Attached sample has one maco which can be run from the toolbar or menu. The process to create the toolbar or menu entries is best described in the LO documentation. See Getting Started with LibreOffice Chapter 14 - Customizing LibreOffice on this link - click here.

Sample: C:\fakepath\ToolMenuMacroSample.ods

edit flag offensive delete link more


Could you perhaps give an example? Or explain how this works?

LibreGuy gravatar imageLibreGuy ( 2017-03-24 22:28:12 +0100 )edit

Will add to answer.

Ratslinger gravatar imageRatslinger ( 2017-03-25 00:30:21 +0100 )edit

Thanks ... pretty cool. I'll look into this.

By the way ... do you always have to enable the macro's when opening the file?

LibreGuy gravatar imageLibreGuy ( 2017-03-25 00:42:29 +0100 )edit

Depending upon where the macro is located, nothing needs to be done. Best to look in macro documentation on same site provided in answer for better clarification.

If this answers your question please click on the ✔ (upper left area of answer).

Ratslinger gravatar imageRatslinger ( 2017-03-25 01:25:09 +0100 )edit

Alright ... but when I clicked your file with the macro it asked me if I wanted to enable the macros. I clicked yes and saved the file. Then when reopening it asked again. There is no way to suppress this behaviour I suppose?

LibreGuy gravatar imageLibreGuy ( 2017-03-25 01:29:41 +0100 )edit

Yes. There are a lot of different things occurring when dealing with macros. It encompasses many, many aspects. This is why I refer to the documentation. Discussion of macros takes on books of information and is not an overnight process. What your specific question deals with is the security. From the menu, Tools->Options. Then under LibreOffice select Security. There on right you probably have Medium selected. Select the Trusted Sources tab & add to Trusted File Locations.

Ratslinger gravatar imageRatslinger ( 2017-03-25 01:49:18 +0100 )edit

Thank you ... that clarifies. I have enough information now to get going. Many thanks for your advice Ratslinger. It's very much appreciated!

LibreGuy gravatar imageLibreGuy ( 2017-03-25 02:01:26 +0100 )edit

answered 2017-03-24 17:20:02 +0100

Well, LO keyboard bindings aren't document-specific.

That means that the task would require also a document's macro that is autoexecuted on the document load, and that would change user's keyboard bindings. To keep things clean, it would also need another macro to clean up when the document is closed, and even when another document is brought to front. (Not to say that it's interesting what would happen when an app crash happens that prevents such cleanup).

And, of course, that would mean another possible target for malicious macros.

But for your first part of question - yes, it's possible to attach a macro to a file, and save it inside a document's module. To do that, you navigate to the document when create the macro, and create new module inside it.

edit flag offensive delete link more


@Mike Kaganski Youre right…without some autocustomizing on load you run into some odd Errors!!

karolus gravatar imagekarolus ( 2017-03-24 17:59:11 +0100 )edit

Thanks for your answers. So, long story short ... what I wanted is not possible and could cause errors. Correct?

LibreGuy gravatar imageLibreGuy ( 2017-03-24 22:27:42 +0100 )edit

answered 2017-03-24 17:26:49 +0100

karolus gravatar image

updated 2017-03-24 17:58:20 +0100

  1. yes →Tools→Makros→…
  2. yes →Tools→Customize→→Keybord……

But you should consider: not any shortcut is available on any OS, some shortcuts are occupied.

if customized file is open but not in focus, there will be an Error after $shortcut

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-03-24 17:12:22 +0100

Seen: 352 times

Last updated: Mar 25 '17