Assigning macros to graphic objects in ONLYOFFICE spreadsheets

7 September 2021 By Ksenija 0 69 views
Share

Use macros to automate routine tasks for your calculations? In this post, we’ll discover one more macro example that can be useful for you.

Assigning macros to graphic objects in ONLYOFFICE spreadsheets

Why assign macros to graphics

In version 6.4 of ONLYOFFICE Docs, we added a new feature in the spreadsheet editor — assigning a macro to be executed when you click on a graphic object. It allows you to turn such objects, for example autoshapes, into a button and set any macro as a handler when pressing it.

This way users can click on the button with the assigned macro to perform some action. It’s more convenient since they don’t need to open the list with macros each time they want to run one of them.

Macro example: automatically diagramming currency exchange rates

To show how it works, we created 3 macros for different currency pairs* (EUR-USD, USD-EUR, and BTC-USD) that get information about the exchange rates for the last several days and fill in the table with the received values.

These macros are assigned to 3 autoshapes. When you click on each autoshape, a macro is executed, the table is filled in with the relevant data and the corresponding chart is rebuilt.

Currency pair USD EUR

Assigning macros to graphic objects in ONLYOFFICE spreadsheets

Macro code is the following:

Currency pair EURUSD

Assigning macros to graphic objects in ONLYOFFICE spreadsheets

Macro code is the following:

Currency pair BTC USD

Assigning macros to graphic objects in ONLYOFFICE spreadsheets

Macro code is the following:

*Please note: In these macros, we used the third-party service CurrencyConverterApi.com to get information about the exchange rates. There is a limit on the number of requests per hour. If this limit is exceeded, the macro will not work. If you want to use this macro, it’s better to register on the service website and use your own key in the macro code.

Add a comment