複数のアドインがリボンを変更しようとしたときに、Roi-KyiBryantのソリューションで問題が発生しました。また、仕事用のコンピューターに管理者アクセス権がないため、のインストールが除外されましたCustom UI Editor。したがって、私と同じボートに乗っている場合は、Excelのみを使用してリボンをカスタマイズする別の例を次に示します。私のソリューションはMicrosoftガイドから派生していることに注意してください。
- リボンをカスタマイズするExcelファイルを作成します。私の場合、複数のアドインがリボンとどのように相互作用できるかを示すために、2つの
.xlamファイルとChart Tools.xlamを作成しました。Priveleged UDFs.xlam
- 作成したファイルごとに、任意のフォルダー名でフォルダーを作成します。
- 作成した各フォルダー内に、フォルダーを追加し
customUIます_rels。
- 各
customUIフォルダ内にcustomUI.xmlファイルを作成します。このcustomUI.xmlファイルには、Excelファイルがリボンとどのように相互作用するかが詳しく説明されています。Microsoftガイドのパート2では、ファイル内の要素について説明していcustomUI.xmlます。
私のcustomUI.xmlファイルはChart Tools.xlam次のようになります
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" xmlns:x="sao">
<ribbon>
<tabs>
<tab idQ="x:chartToolsTab" label="Chart Tools">
<group id="relativeChartMovementGroup" label="Relative Chart Movement" >
<button id="moveChartWithRelativeLinksButton" label="Copy and Move" imageMso="ResultsPaneStartFindAndReplace" onAction="MoveChartWithRelativeLinksCallBack" visible="true" size="normal"/>
<button id="moveChartToManySheetsWithRelativeLinksButton" label="Copy and Distribute" imageMso="OutlineDemoteToBodyText" onAction="MoveChartToManySheetsWithRelativeLinksCallBack" visible="true" size="normal"/>
</group >
<group id="chartDeletionGroup" label="Chart Deletion">
<button id="deleteAllChartsInWorkbookSharingAnAddressButton" label="Delete Charts" imageMso="CancelRequest" onAction="DeleteAllChartsInWorkbookSharingAnAddressCallBack" visible="true" size="normal"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
私のcustomUI.xmlファイルはPriveleged UDFs.xlam次のようになります
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" xmlns:x="sao">
<ribbon>
<tabs>
<tab idQ="x:privelgedUDFsTab" label="Privelged UDFs">
<group id="privelgedUDFsGroup" label="Toggle" >
<button id="initialisePrivelegedUDFsButton" label="Activate" imageMso="TagMarkComplete" onAction="InitialisePrivelegedUDFsCallBack" visible="true" size="normal"/>
<button id="deInitialisePrivelegedUDFsButton" label="De-Activate" imageMso="CancelRequest" onAction="DeInitialisePrivelegedUDFsCallBack" visible="true" size="normal"/>
</group >
</tab>
</tabs>
</ribbon>
</customUI>
- 手順1で作成したファイルごとに、
.zipファイル名の末尾にaを付けます。私の場合、名前を、、に変更しChart Tools.xlamました。Chart Tools.xlam.zipPrivelged UDFs.xlamPriveleged UDFs.xlam.zip
- 各
.zipファイルを開き、_relsフォルダーに移動します。手順3で作成し.relsたフォルダにファイルをコピーします。テキストエディタで各ファイルを編集します。Microsoftガイドから_rels .rels
最後の<Relationship>要素と終了
<Relationships>要素の間に、ドキュメントファイルとカスタマイズファイルの間に関係を作成する行を追加します。フォルダ名とファイル名を正しく指定してください。
<Relationship Type="http://schemas.microsoft.com/office/2006/
relationships/ui/extensibility" Target="/customUI/customUI.xml"
Id="customUIRelID" />
私の.relsファイルはChart Tools.xlam次のようになります
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
<Relationship Type="http://schemas.microsoft.com/office/2006/relationships/ui/extensibility" Target="/customUI/customUI.xml" Id="chartToolsCustomUIRel" />
</Relationships>
私の.relsファイルはPriveleged UDFs次のようになります。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
<Relationship Type="http://schemas.microsoft.com/office/2006/relationships/ui/extensibility" Target="/customUI/customUI.xml" Id="privelegedUDFsCustomUIRel" />
</Relationships>
.rels各.zipファイルのファイルを.rels、前の手順で変更した1つまたは複数のファイルに置き換えます。
- 作成したフォルダをコピーして、ファイル
.customUIのホームディレクトリに貼り付けます。.zip
.zip作成したExcelファイルからファイル拡張子を削除します。
- ファイルを作成した場合
.xlamは、Excelに戻って、Excelアドインにファイルを追加します。
- 該当する場合は、各アドインでコールバックを作成します。ステップ4では
onAction、ボタンにキーワードがあります。キーワードは、包含要素がトリガーされると、ExcelアプリケーションがキーワードonActionの直後に引用符で囲まれたサブルーチンをトリガーすることを示します。onActionこれはコールバックとして知られています。私の.xlamファイルにはCallBacks、コールバックサブルーチンを含めたというモジュールがあります。

私のCallBacksモジュールはChart Tools.xlam次のようになります
Option Explicit
Public Sub MoveChartWithRelativeLinksCallBack(ByRef control As IRibbonControl)
MoveChartWithRelativeLinks
End Sub
Public Sub MoveChartToManySheetsWithRelativeLinksCallBack(ByRef control As IRibbonControl)
MoveChartToManySheetsWithRelativeLinks
End Sub
Public Sub DeleteAllChartsInWorkbookSharingAnAddressCallBack(ByRef control As IRibbonControl)
DeleteAllChartsInWorkbookSharingAnAddress
End Sub
私のCallBacksモジュールはPriveleged UDFs.xlam次のようになります
オプション明示
Public Sub InitialisePrivelegedUDFsCallBack(ByRef control As IRibbonControl)
ThisWorkbook.InitialisePrivelegedUDFs
End Sub
Public Sub DeInitialisePrivelegedUDFsCallBack(ByRef control As IRibbonControl)
ThisWorkbook.DeInitialisePrivelegedUDFs
End Sub
要素が異なれば、コールバックサブルーチンのシグネチャも異なります。ボタンの場合、必要なサブルーチンパラメータはByRef control As IRibbonControlです。必要なコールバック署名に準拠していない場合、VBAプロジェクトのコンパイル中にエラーが発生します。Microsoftガイドのパート3では、すべてのコールバック署名を定義しています。
完成した例は次のようになります

いくつかの締めくくりのヒント
- アドインでリボン要素を共有する場合は、
idQandxlmns:キーワードを使用します。私の例では、Chart Tools.xlamとのPriveleged UDFs.xlam両方が、とに等しい'sを持つ要素にアクセスできidQます。これを機能させるには、が必要です。ファイルの最初の行で名前空間を定義しました。Microsoftガイドの「FluentUIをカスタマイズする2つの方法」セクションに詳細が記載されています。x:chartToolsTabx:privelgedUDFsTabx:customUI.xml<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" xmlns:x="sao">
- アドインでExcelに付属のリボン要素にアクセスする場合は、
isMSOキーワードを使用します。Microsoftガイドの「FluentUIをカスタマイズする2つの方法」セクションに詳細が記載されています。