# Attach macro to a file? [closed]

Hello,

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 reopen merge delete

### Closed for the following reason the question is answered, right answer was accepted by Alex Kemp close date 2020-09-28 14:10:04.377885

Sort by » oldest newest most voted

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.

Edit:

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.

more

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

( 2017-03-24 22:28:12 +0200 )edit

( 2017-03-25 00:30:21 +0200 )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?

( 2017-03-25 00:42:29 +0200 )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.

( 2017-03-25 01:25:09 +0200 )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?

( 2017-03-25 01:29:41 +0200 )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.

( 2017-03-25 01:49:18 +0200 )edit

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

( 2017-03-25 02:01:26 +0200 )edit

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.

more

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

( 2017-03-24 17:59:11 +0200 )edit

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

( 2017-03-24 22:27:42 +0200 )edit
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

more