Main Content

Create Microsoft Excel Add-in from MATLAB Function Using Library Compiler App

This example shows how to use the Library Compiler app in MATLAB® Compiler™ to package a MATLAB function into a Microsoft® Excel® add-in containing a custom function for use within Excel. Alternatively, if you want to create an add-in from the MATLAB command window using a programmatic approach, see Create Excel Add-In from MATLAB.

Before you begin, verify that you have met all of the Excel target requirements for MATLAB Compiler. For details, see Excel Target Requirements and Limitations for MATLAB Compiler.


To generate the Visual Basic® files, enable Trust access to the VBA project object model in Excel. If you do not do this, you can manually create the add-in by importing the .bas file into Excel.

  1. On the MATLAB Apps tab, on the far right of the Apps section, click the arrow. In Application Deployment, click Library Compiler.

    Alternately, you can open the Library Compiler app by entering libraryCompiler at the MATLAB prompt.

  2. In the MATLAB Compiler project window, specify the main file of the MATLAB application that you want to deploy.

    1. In the Main File section of the toolstrip, click .

    2. In the Add Files window, browse to the location of your MATLAB function. For this example, select the file mymagic.m.

      mymagic.m is added to the list of exported functions.

      Library Compiler with Excel Add-in type selected and mymagic.m in the exported function section

  3. In the Packaging Options section of the toolstrip, decide whether to include the MATLAB Runtime installer in the generated application by selecting one of the options:

    • Runtime downloaded from web — Generate an installer that downloads the MATLAB Runtime and installs it along with the deployed MATLAB application. You can specify the file name of the installer.

    • Runtime included in package — Generate an application that includes the MATLAB Runtime installer. You can specify the file name of the installer.


      The first time you select this option, you are prompted to download the MATLAB Runtime installer.

  4. Next, define the name of your add-in and verify the class mapping for the .m file that you are building into your application.

    1. The Library Name field is automatically populated with mymagic as the name of the assembly. Rename it as xlmagic. The same name is followed through in the implementation of the add-in.

    2. Verify that the function defined in mymagic.m is mapped into xlmagicclass. Double-click on the class to change the class name.

    Library Compiler Class Name section with class name xlmagicclass for the method mymagic

  5. Customize the packaged application and its appearance:

    • Library information — Editable information about the deployed application. The generated installer uses this information to populate the installed application metadata. See Customize the Installer.

    • Additional installer options — Edit the default installation path for the generated installer and selecting custom logo. See Change the Installation Path.

    • Files required for your library to run — Additional files required by the generated application to run. These files are included in the generated application installer. See Manage Required Files in Compiler Project.

    • Files installed for your end user — Files that are installed with your application.

      See Specify Files to Install with Application.

    • Additional runtime settings — Platform-specific options for controlling the generated executable. See Additional Runtime Settings.

  6. To generate the packaged add-in, click Package.

    In the Save Project dialog box, specify the location to save the project.

  7. In the Package dialog box, verify that Open output folder when process completes is selected.

    When the packaging process is complete, examine the generated output.

    • Three folders are generated in the target folder location: for_redistribution, for_redistribution_files_only, and for_testing.

      For further information about the files generated in these folders, see Files Generated After Packaging MATLAB Functions.

    • PackagingLog.html — Log file generated by MATLAB Compiler.

  8. To use your add-in, see Distribute Add-Ins and Integrate into Microsoft Excel.

See Also

| |

Related Topics