Main Content

Distribute Add-Ins and Integrate Into Microsoft Excel

Integration Process Overview

Each MATLAB® Compiler™ component is built as a COM object that you can access from Microsoft® Excel® through Microsoft Visual Basic® for Applications (VBA). You can integrate the MATLAB Compiler components into Excel using the VBA programming environment.

For general information on programming in Visual Basic, refer to the VBA documentation provided with Excel.

Key Tasks for Microsoft Excel End User

Verify that you have received all necessary files from the MATLAB programmer.Files To Distribute To End Users
Verify registry permissions for the add-in file and associated DLL component.Add-In and COM Component Registration
Execute your generated functions and create macros.Execute Functions and Create Macros
Install MATLAB Runtime on target systems and update system paths.Install and Configure MATLAB Runtime
Use the Excel add-in.Add-In Installation and Distribution

Files To Distribute To End Users

After you create your Excel add-in, distribute the generated installer to your end user. The installer installs the packaged add-in and MATLAB Runtime.

If you do not create an installer, distribute the files that the Library Compiler generates in the for_redistribution_files_only folder. For a list of files generated in each folder, see Files Generated After Packaging MATLAB Functions.

Add-In and COM Component Registration


COM components are used in both MATLAB Compiler and MATLAB Compiler SDK™, therefore some of the instructions relating to building and packaging COM components and add-ins can be shared between products.

When you create your COM component, it is registered in either HKEY_LOCAL_MACHINE or HKEY_CURRENT_USER, based on your log-in privileges.

If you find you need to change your run-time permissions due to security standards imposed by Microsoft or your installation, you can do one of the following before deploying your COM component or add-in:

  • Log on as administrator before running your COM component or add-in

  • Run the following mwregsvr command prior to running your COM component or add-in, as follows:

    mwregsvr [/u] [/s] [/useronly] project_name.dll 

    • /u allows any user to unregister a COM component or add-in for this server

    • /s runs this command silently, generating no messages. This is helpful for use in silent installations.

    • /useronly allows only the currently logged-in user to run the COM component or add-in on this server


If your COM component is registered in the USER hive, it will not be visible to Windows Vista™ or Windows® 7 users running as administrator on systems with UAC (User Access Control) enabled.

If you register a component to the USER hive under Windows 7 or Windows Vista, your COM component may fail to load when running with elevated (administrator) privileges.

If this occurs, do the following to re-register the component to the LOCAL MACHINE hive:

  1. Unregister the component with this command:

    mwregsvr /u /useronly my_dll.dll

  2. Reregister the component to the LOCAL MACHINE hive with this command:

    mwregsvr my_dll.dll

Add-In Installation and Distribution

Since Microsoft Excel add-ins are written directly to the distrib folder by MATLAB Compiler, you and your end users install them exactly as you install the Function Wizard in Installation of the Function Wizard.

Call Add-In Code from Excel Spreadsheet

To run the executable code from a cell in the Excel spreadsheet, invoke the add-in name with a method call. For example, if you deployed a piece of MATLAB code called mymagic.m, or a figure called mymagic.fig, you invoke that code by entering the following in a cell in the spreadsheet:



If the method call does not evaluate immediately, press Ctrl, Shift, and Enter simultaneously.

Related Topics