Two ONLYOFFICE macros: highlight duplicates and go to the next empty row

Our users asked us how to recreate some VBA macros they were using in Excel. In this post, we’ll show how to do it on two simple examples.

macros in onlyoffice

About ONLYOFFICE macros

ONLYOFFICE macros use JavaScript language syntax and ONLYOFFICE Document Builder API scripting notation. This means that you won’t be able to use VBA macros until you recreate them using JavaScript.

We chose to use JavaScript for our macros because:
 

  • It is cross-platform,
  • it is really easy to use,
  • you can use the code you wrote as a macro or as a plugin.

Also, our macros are safe because they do not have any access to the system. They are just JS code that runs in the same window with the editors.

How to start writing your macro

 

  1. In spreadsheet editor, open the Plugins tab and click Macros.
  2. Click “New” in the window that appeared.
  3. Consult API documentation to write the script.
Example #1: Highlight duplicates

Let’s write a macro to highlight duplicates in the selected area with different colors to recognize duplicated values quickly. We’ll use this simple VBA macro as a base.

Here is the resulting script with comments for you to understand how it’s done. The colors are determined in macro code.

Here’s what we get with this macro:

ONLYOFFICE macro highlight duplicates

Example #2

This one finds the next available blank row in a worksheet. We took this VBA macro as an example and created this script:

This code will help you select the next empty row (we’ll bring scrolling in one of the next versions).

Note that the macro will skip any blanks that are between your data but not at the very end of it.

How to get help with macros

If you need help with writing macros or the method you need is absent from our API, post an issue on GitHub.

Useful links

ONLYOFFICE on GitHub

Article on starting writing plugins. Read now>>

Plugin example: fill the cells with color and turn your worksheet into an image. Check it out>>

 

Add a comment