Macro 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
Acronym full forms
Identifies all acronyms in the document and adds their full forms in comments.
Automatic bookmark generation
Automatically generates bookmarks for all heading paragraphs in the document, using the heading text as the bookmark name.
Calculate time to read
Analyzes the text content of the entire document, counts the number of words, adjusts for the text complexity, and calculates how long it would take an average adult to read it.
Create content control list
Creates a ContentControlList from all single-level numbered lists throughout the document, as well as from the manually selected text section.
Create custom header
Creates a custom header with an image and a title. The image is represented as a base64 string in the code, which can be customized or replaced as needed.
Custom header and footer generation
Applies predefined headers and footers to all pages in the document.
Delete bookmark
Searches for bookmarks containing a specific word in their text and deletes them from the document.
Generate hyperlinks
Generates and inserts hyperlinks instead of text URLs.
Generate table of contents
Generates a table of contents by scanning the document for headings.
Generate word definitions
Generates word definitions in your document using the Dictionary API offered by API Ninjas.
Highlight predefined keywords
Highlights predefined keywords in text document.
Identify overused words
Analyzes the frequency of words in a document and identifies overused words based on specified thresholds.
Insert text
Inserts text into the document at the current cursor position.
Insert unique id
Inserts a unique id into a form document.
Insert watermark
Inserts or removes a custom watermark on every page of the document.
Paragraphs to table
Converts a list of numbered paragraphs into a table.
Remove empty tables
Removes all the empty tables from the document.
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 text properties
Resets the text properties of all the paragraphs in a document to the default settings.
Search for keyword in comments
Marks comments containing a specific keyword as solved in a document.
Sort tables
Automatically sorts table rows alphabetically or numerically based on the selected column.
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.
Check data mismatch
Highlights cells with data type mismatches based on column majority vote, starting from B2 by default, with configurable header offsets.
Complete address information
Completes the basic address data with detailed address information and inserts it into a spreadsheet.
Conditional formatting rules
Applies multiple conditional formatting rules to the selected range.
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.
Delete comments
Deletes comments from a specified range of cells in the active worksheet.
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.
Remove duplicate sheet
Identifies and removes duplicate sheets in the spreadsheet.
Set column width
Sets the width for the column B.
Sheet merger
Merges data from all sheets into the active sheet by copying the used range of each sheet and appending it.
Sort range
Automatically sorts a selected range or the entire used range in a spreadsheet.
Split data sheets
Splits large sheets containing extensive datasets into multiple sheets if they exceed a specified row limit.
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.
Weighted average function
Creates a custom function to calculate a weighted average.
Write data to worksheet cell
Writes the data (the Hello world phrase) to the worksheet third column of the fourth row.
Presentation editor
Adjust indentation
Adjusts the first line indentation for all paragraphs in your presentation.
Align charts
Aligns charts and text boxes on every slide.
Apply corporate branding
Applies corporate branding styles to a presentation, including text color, font, and logo placement.
Apply font style
Applies a consistent font style across all the slides.
Autoplaceholder
Automatically fills empty text boxes on slides with placeholder content and arranges texts in a structured format.
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.
Content alignment tool
Consistently aligns text boxes and images throughout the entire presentation.
Count number of shapes
Counts the total number of shapes in a presentation by iterating through all slides and displays the count on a newly created slide.
Create slides from list items
Creates new slides based on the listed items in the current slide. Each list item becomes a slide title.
Format bullet points
Applies consistent formatting to bullet points.
Format slide titles
Formats the title of each slide in a presentation. It sets the font, font size, justification, and vertical text alignment for the title.
Hyperlinks to QR codes
Converts all the hyperlinks in the presentation into QR codes using an external API.
Remove empty paragraphs
Deletes all unnecessary blank paragraphs across the entire presentation.
Remove empty text boxes
Deletes all empty text box shapes throughout the entire presentation.
Remove extra spaces
Removes extra spaces from all text in all slides of a presentation.
Remove shapes from slides
Removes shapes from slides in a presentation.
Split slides
Splits slides in a presentation that contain more than 100 words into multiple slides.
Table to chart
Generates a chart based on the selected table data.
PDF 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.
Change validation rules
Changes the validation rules of the number and email fields in the document.
Clear checkboxes
Clears all checkboxes in the document.
Count form fields
Counts the number of form fields in a document and categorizes them by type.
Keyword match in form keys
Highlights form fields based on a keyword match in the form key.
Mask card numbers
Applies the mask to all forms with the specified form key to hide card numbers.
Reset all forms
Clears all fields if necessary, for example after printing the document.
Resize picture form
Resizes PictureForms based on a predefined size or aspect ratio across the document.
Set checkbox tip text
Sets the desired tip text to all checkboxes with a certain key.
Set form background color
Changes the background color of all form fields on focus.
Set USA date format
Sets all date form formats to USA one.
Update date field
Sets the current date to all date form fields in the document.
Validate form fields
Highlights empty or unrequired text fields in a document with desired colors.
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.