logo
search
VBA & Macro Problems

How to Convert VBA Code for Outlook Emails to Office Scripts

Kushani NimanthikaKushani Nimanthika Oct 9, 2026 868 views

Question details

The user wants to convert an Excel VBA procedure that automates sending an Outlook email with an attachment into Office Scripts.

Converting VBA Code for Outlook Emails to Office Scripts
Product
Microsoft Excel
Device & OS
not provided
Scenario
Migrating from desktop VBA macros to cloud-based Office Scripts for email automation and workbook manipulation.
Observed behavior
The user needs to replicate a specific workflow (hiding a button, saving the workbook, attaching it to an Outlook email, sending it, and unhiding the button) using Office Scripts instead of VBA.
Before you start

Note that Office Scripts and VBA use entirely different object models. Direct email automation in Office Scripts requires integration with external tools like Power Automate, as Office Scripts cannot directly control the Outlook desktop application.

Solution 1Recommended

Replicate the Workflow Using Power Automate and Office Scripts

Since Office Scripts cannot interact directly with the Outlook desktop client, you must split the task. Use Office Scripts to handle the Excel UI, and Power Automate to handle the email.

Office Scripts run in the cloud and do not have access to the Outlook desktop application object model (like 'Outlook.Application' in VBA). To successfully replicate this macro workflow, you need to rely on Microsoft Power Automate to bridge the gap between Excel and Outlook.

1
Create the Initial Office Script

In Excel on the web, go to the Automate tab and create a new script. Write the code to hide the specific button shape on your worksheet.

2
Build a Power Automate Flow

Open Power Automate and create a new flow. Use 'For a selected row' or a manual trigger from Excel to initiate the workflow.

3
Run the Office Script via Power Automate

Add the 'Run script' action from the Excel Online connector in your flow to execute the script that hides the button.

4
Add the Email Action

Add the 'Send an email (V2)' action from the Office 365 Outlook connector. Configure the recipient, subject, and use the 'Get file content' action to attach your Excel workbook dynamically.

5
Restore Button Visibility

Add a final 'Run script' action at the end of your flow to execute a second Office Script that unhides the original button.

Replicate the Workflow Using Power Automate and Office Scripts
Seek Specialized Help: For specific Office Scripts TypeScript syntax or Power Automate logic, posting your exact scenario in the Office Development section of Microsoft Q&A is highly recommended.
Free Microsoft Office alternative

Run Your VBA Macros Natively with WPS Office

Skip the complex conversion to Office Scripts and Power Automate. WPS Office provides excellent native support for VBA macros, allowing you to run your existing desktop automation scripts seamlessly. It is a free, lightweight, and highly compatible alternative to Microsoft Office.

  1. 1. Download and Install WPS Office: Get the free version of WPS Office from the official website and install it on your device.
  2. 2. Open Your Macro Workbook: Open your existing .xlsm file containing the Outlook email VBA code in WPS Spreadsheet.
  3. 3. Enable and Run Macros: Navigate to the Developer tab, enable macros, and run your original VBA code directly without needing to rewrite it.
Native support for running Excel VBA macros without needing cloud workarounds.Highly compatible with Microsoft Excel formats (.xlsx, .xlsm).Free and lightweight alternative to Microsoft Office.Familiar user interface ensures immediate productivity and easy migration.
microsoft office alternative - wps office

Frequently Asked Questions

Why can't Office Scripts directly automate Outlook like VBA?

Office Scripts execute in a secure cloud environment via Excel on the web. This means they lack access to local COM objects and desktop applications like Outlook, which VBA traditionally utilizes for cross-application automation.

Can I trigger an Office Script from a button click like in VBA?

Yes, you can insert a button shape in Excel on the web or desktop and assign an Office Script to it, which functions very similarly to assigning a macro to a button.

Is Microsoft Graph a valid alternative for sending emails via scripts?

Yes, developers can use the Microsoft Graph API within custom web add-ins or external applications to send emails. However, for most users migrating from standard VBA macros, using Power Automate is much more straightforward.

Will my existing VBA code work in WPS Office without conversion?

In most cases, standard VBA code—including UI manipulation and basic automation—works seamlessly in WPS Office. This allows you to continue using your macros natively, avoiding the need to rewrite them into Office Scripts.