[PowerPoint] How to Execute Macros from the Ribbon Using Custom UI Editor

目次

Background

When creating tools with PowerPoint VBA, placing buttons directly on slides can look unpolished. Adding a custom tab to the Ribbon (header area) provides a seamless, application-like experience.

This article summarizes how to use the Custom UI Editor Tool to add a custom tab and execute a UserForm.

1. Preparation of PowerPoint File

First, prepare the PowerPoint file (.pptm) and the VBA code.

Important: When calling a Sub from the Ribbon, the argument control As IRibbonControl is required.

VBA Code (Standard Module)

' The callback signature for the ribbon button must include (control As IRibbonControl)
Sub ShowUserForm(control As IRibbonControl)
    UserForm1.Show
End Sub

2. Obtaining and Installing the Tool

Since the official installer often fails on modern systems, manual adjustments are required after downloading.

Download

Office Custom UI Editor [https://github.com/OfficeDev/office-custom-ui-editor]

  1. Click Code and select Download ZIP.
  2. Unzip the downloaded folder.

Installation (Workaround for Validation Error)

If setup.exe fails with “Application validation failed,” follow these steps to rename files by removing the .deploy extension.

Target Folder: publish\Application Files\CustomUIEditor_4_0_0_0

Original File NameNew File Name
CustomUIEditor.exe.config.deployCustomUIEditor.exe.config
CustomUIEditor.exe.deployCustomUIEditor.exe
CustomUIEditor.ico.deployCustomUIEditor.ico

Target Folder: publish\Application Files\CustomUIEditor_4_0_0_0\Samples

Original File NameNew File Name
Custom OutSpace.xml.deployCustom OutSpace.xml
Custom Tab.xml.deployCustom Tab.xml
Excel - A Custom Tab.xml.deployExcel - A Custom Tab.xml
Repurpose.xml.deployRepurpose.xml
Word - Group on Insert Tab.xml.deployWord - Group on Insert Tab.xml

Target Folder: publish\Application Files\CustomUIEditor_4_0_0_0\Schemas

Original File NameNew File Name
CustomUI.xsd.deployCustomUI.xsd
CustomUI14.xsd.deployCustomUI14.xsd

After renaming, run CustomUIEditor.exe directly from the folder.

3. Editing the Ribbon XML

  1. Launch CustomUIEditor.exe.
  2. Click Open and select your PowerPoint file (.pptm).
  3. Paste the following code into the editor window.

XML Code

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
  <ribbon>
    <tabs>
      <tab id="CustomTab" label="Code">
        <group id="CustomGroup" label="Custom UserForm">
          <button id="ShowUserFormButton" label="UserForm1" size="large" onAction="ShowUserForm" />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>
  1. Click Save.

Summary

When you open the PowerPoint file, a new tab named “Code” will appear in the Ribbon. Clicking the “UserForm1” button will execute the macro.

Key Points

  • VBA: The Sub must accept control As IRibbonControl.
  • XML: The onAction attribute must match the VBA Sub name exactly.
  • Tool: Removing .deploy extensions allows the tool to run without installation.
よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

私が勉強したこと、実践したこと、してることを書いているブログです。
主に資産運用について書いていたのですが、
最近はプログラミングに興味があるので、今はそればっかりです。

目次