複数のアドインがリボンを変更しようとしたときに、Roi-Kyi Bryantのソリューションで問題が発生しました。また、のインストールを除外している仕事用コンピューターの管理アクセス権も持っていません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>
- 以下のために、各ファイルあなたは、接尾辞A、ステップ1で作成した
.zip自分のファイル名に。私の場合、私は名前を変更Chart Tools.xlamするChart Tools.xlam.zip、とPrivelged UDFs.xlamしますPriveleged UDFs.xlam.zip。
- 各
.zipファイルを開き、_relsフォルダに移動します。手順3で作成.relsした_relsフォルダーにファイルをコピーします。各 .relsファイルをテキストエディターで編集します。Microsoftガイドから
最終<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、前のステップで変更したファイルで置き換えます。
.customUI作成したフォルダーをコピーして、.zipファイルのホームディレクトリに貼り付けます。
.zip作成したExcelファイルからファイル拡張子を削除します。
.xlamファイルを作成した場合は、Excelに戻って、Excelアドインに追加します。
- 必要に応じて、各アドインでコールバックを作成します。ステップ4では
onAction、ボタンにキーワードがあります。onActionキーワードを含む要素がトリガされたとき、Excelアプリケーションが直後引用符で包まサブルーチントリガする、ことを示す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では、すべてのコールバック署名を定義しています。
これが私の完成した例です

いくつかの終了のヒント
- アドインでリボン要素を共有する場合は、
idQand xlmns:キーワードを使用します。私の例では、Chart Tools.xlamとのPriveleged UDFs.xlam両方が、とidQ等しいx:chartToolsTabおよびの要素にアクセスできますx:privelgedUDFsTab。これが機能するには、x:が必要です。また、名前空間を最初の行に定義しましたcustomUI.xmlファイルの<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" xmlns:x="sao">。詳細については、MicrosoftガイドのFluent UIをカスタマイズする2つの方法のセクションを参照してください。
- アドインがExcelに付属のリボン要素にアクセスするようにするには、
isMSOキーワードを使用します。詳細については、MicrosoftガイドのFluent UIをカスタマイズする2つの方法のセクションを参照してください。