Samples
The following examples will show you how to use ONLYOFFICE macros and compare the JavaScript code with Microsoft Visual Basic for Applications code so that you could see the difference and understand what can be done to convert the VBA code to ONLYOFFICE macros.
Text document editor
📄️ Add state from zip code
Adds the "State" label and the text form prefilled with "CA" if the zip code of California is entered. It can be extended by using API to prefill "State" when entering the zip code.
📄️ Generate hyperlinks
Generates and inserts hyperlinks instead of text URLs.
📄️ Generate word definitions
Generates word definitions in your document using the Dictionary API offered by API Ninjas.
📄️ Insert text
Inserts text into the document at the current cursor position.
📄️ Insert unique id
Inserts a unique id into a form document.
📄️ Mask card numbers
Applies the mask to all forms with the specified form key to hide card numbers.
📄️ Remove extra spaces
Removes extra spaces in text document.
📄️ Replace words in document
Searches for a word throughout the document and replaces it with the given replacement word.
📄️ Reset all forms
Clears all fields if necessary, for example after printing the document.
📄️ Set USA date format
Sets all date form formats to USA one.
Spreadsheet editor
📄️ Add chart
Adds a new chart to the selected cell range.
📄️ Add comments and change cell colors in spreadsheet
Adds comments to the cells in the selection and can also change the background color of the cells.
📄️ Change cell background color
Sets the background color of the cell B3 to blue.
📄️ Change cell font color
Sets the font color of the cell B4 to red.
📄️ Complete address information
Completes the basic address data with detailed address information and inserts it into a spreadsheet.
📄️ Currency conversion
Converts a base currency into multiple desired target currencies. It can also fetch historical currency values for a specific date. Uses the Currency Conversion API from currencyapi.
📄️ Find company logos
Searches for a company logo throughout the spreadsheet using the Logo API offered by API Ninjas.
📄️ Format range as table
Formats the range of cells A1:D10 as a table.
📄️ Hide or unhide rows and columns
Hides or unhides the specified rows and/or columns in the spreadsheet.
📄️ Highlight duplicates
Highlights duplicates in the selected area with different colors to recognize duplicated values quickly.
📄️ Import CSV/TXT data
Imports data from remote CSV/TXT files into the spreadsheet.
📄️ Import hyperlinks
Imports hyperlinks between different worksheets in the spreadsheet.
📄️ Make cell font bold
Sets the font of the cell A2 to bold.
📄️ Merge cell range
Merges the selected cell range.
📄️ Next blank row
Finds the next available blank row in a worksheet. This macro allows you to get the blank at the very end of your data (not between it).
📄️ Recalculate worksheet values
Repeatedly recalculates worksheet cell values within one-second intervals.
📄️ Set column width
Sets the width for the column B.
📄️ Sum of highlighted cells
Sums the answer of all highlighted cells in a spreadsheet.
📄️ Unhide all rows and columns
Unhides all the rows and columns in the active spreadsheet.
📄️ Unmerge cell range
Unmerges the selected cell range.
📄️ Write data to worksheet cell
Writes the data (the Hello world phrase) to the worksheet third column of the fourth row.
Presentation editor
📄️ Change background color
Sets blue color as the background of even indexed slides, if it is odd sets an image.
📄️ Change font family and size
Changes the font family and/or size on all the slides in your presentation.
📄️ Remove shapes from slides
Removes shapes from slides in a presentation.
Support
If you want to request a feature or report a bug regarding macros, use the issues section on GitHub.
You can also request a macro sample by contacting us at marketing@onlyoffice.com.