Перейти до основного вмісту

Додавання іконки запуску додатків у стрічку меню Excel 2007-2019

Додати іконку запуску додатку (Addon) у головну стрічку меню в MS Excel 2007-2019 не можливо простими засобами розробника.

На 

https://stackoverflow.com/questions/8850836/how-to-add-a-custom-ribbon-tab-using-vba

знайшов працюючий метод.

Що в свою чергу базується на порадах Microsoft 

https://learn.microsoft.com/en-us/previous-versions/office/developer/office-2007/aa338202(v%3Doffice.12)#using-callbacks

Метод наступний

  1. Create Excel file/files whose ribbons you want to customise. In my case, I've created two .xlam files, Chart Tools.xlsm , to demonstrate how multiple add-ins can interact with the Ribbon.
  2. Create a folder, with any folder name, for each file you just created.
  3. Inside each of the folders you've created, add a customUI and _rels folder.
  4. Inside each customUI folder, create a customUI.xml file. The customUI.xml file details how Excel files interact with the ribbon. Part 2 of the Microsoft guide covers the elements in the customUI.xml file.

My customUI.xml file for Chart Tools.xlam looks like this

<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>
  1. For each file you created in Step 1, suffix a .zip to their file name. In my case, I renamed Chart Tools.xlam to Chart Tools.xlam.zip.
  2. Open each .zip file, and navigate to the _rels folder. Copy the .rels file to the _rels folder you created in Step 3. Edit each .rels file with a text editor. From the Microsoft guide

Between the final <Relationship> element and the closing <Relationships> element, add a line that creates a relationship between the document file and the customization file. Ensure that you specify the folder and file names correctly.

<Relationship Type="http://schemas.microsoft.com/office/2006/
  relationships/ui/extensibility" Target="/customUI/customUI.xml" 
  Id="customUIRelID" />

My .rels file for Chart Tools.xlam looks like this

<?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>
  1. Replace the .rels files in each .zip file with the .rels file/files you modified in the previous step.
  2. Copy and paste the .customUI folder you created into the home directory of the .zip file/files.
  3. Remove the .zip file extension from the Excel files you created.
  4. If you've created .xlsm files, back in Excel, add them to your Excel add-ins.
  5. If applicable, create callbacks in each of your add-ins. In Step 4, there are onAction keywords in my buttons. The onAction keyword indicates that, when the containing element is triggered, the Excel application will trigger the sub-routine encased in quotation marks directly after the onAction keyword. This is known as a callback. In my .xlsm files, I have a module called CallBacks where I've included my callback sub-routines.

CallBacks Module

My CallBacks module for Chart Tools.xlam looks like

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

Different elements have a different callback sub-routine signature. For buttons, the required sub-routine parameter is ByRef control As IRibbonControl. If you don't conform to the required callback signature, you will receive an error while compiling your VBA project/projects. Part 3 of the Microsoft guide defines all the callback signatures.


Перелік, іконок, котрі можна використовуати для стірчки меню, тут
https://bert-toolkit.com/imagemso-list.html


Коментарі

Популярні дописи з цього блогу

Подключение Cisco 7911/7912 по SIP к Asterisk

Аппарат Cisco IP Phone 7911 по-умолчанию настроен на использование протокола SCCP. Можно в Asterisk указать использование модулей SCCP, но для единообразия удобнее использовать SIP. Для использования протокола SIP в аппарате Cisco 7911 нужно обновить программное обеспечение.  Код обновления для загрузки в аппарат нужно скачать с сервера Cisco: http://tools.cisco.com/support/downloads/pub/Redirect.x?mdfid=278875240 Самое последнее обновление (на данный момент версия 9.3) может не работать c Asterisk, с  версии 9.X Cisco переходит на использование только TCP для SIP соединений. Поэтому для использования UDP удобнее скачать обновление версии 8.5.2 или 8.5.4. Может понадобится  вначале   установить обновление 8.5.2, а затем 8.5.4. Например, для обновления с SCCP11.8-2-2SR-4S надо вначале установить 8.5.2 Обновление будет производится с сервера  TFTP, поэтому д ля начала нужно настроить сервер DHCP, TFTP. Причем в DHCP нужно настроить опцию 150, которая используется для указания аппа

Панель инструментов Remmina в полноэкранном режиме Ubuntu 12.04

Пакет Remmina 0.9.99 (протокол RDP) в системе Ubuntu 12.04 используется как клиент для доступа к терминальному серверу. Обнаружено странное поведение панели инструментов в полноэкранном режиме на терминальном сервере- панель инструментов исчезает и невозможно перейти в другое окно или закрыть сеанс. Для сворачивания окна можно использовать комбинацию клавиш CTRL+F9. Комбинации клавиш задаются в настройках Remmina, а CTRL нужно, чтобы комбинацию не перехватил терминальный сервер. В настройках Remmina есть параметр "Спрятать панель инструментов в полноэкранном режиме". Но иногда, даже если не указан этот параметр, меню не отображается. Можно, не закрывая терминальную сессию, изменить этот параметр на противоположный и после возврата в сессию, меню начнет появляться. В следующий раз перед открытием новых сессий в Remmina нужно правильно указать значение этого параметра. Размер иконок в панели инструментов можно изменить через основное меню Remmina

Изменение размера бумаги LibreOffice(OpenOffice)

Если при установке Ubuntu указать локаль «USA», то размер бумаги по-умолчанию установится «Letter». Если потом через «Система- Администрирование- Локализации» изменить локаль на «Украинский» («Русский»), изменится язык системы, формат даты, но размер бумаги по-умолчанию и единица измерения останутся прежними.  Совет нашел в http://www.nixp.ru/recipes/%D0%9A%D0%B0%D0%BA-%D1%83%D1%81%D1%82%D0%B0%D0%BD%D0%BE%D0%B2%D0%B8%D1%82%D1%8C-%D1%80%D0%B0%D0%B7%D0%BC%D0%B5%D1%80-%D0%B1%D1%83%D0%BC%D0%B0%D0%B3%D0%B8-%D0%B2-OpenOffice-org-%D0%BF%D0%BE-%D1%83%D0%BC%D0%BE%D0%BB%D1%87%D0%B0%D0%BD%D0%B8%D1%8E-%28libpaper%29.html Нужно в терминале запустить sudo dpkg-reconfigure libpaper1 В открывшемся списке выбрать формат А4. Можно напрямую в файле конфигурации (/etc/papersize) указать размер А4. Проверить можно в LibreOffice(OpenOffice) через меню «Формат-Страница». Еще в LibreOffice(OpenOffice) нужно изменить единицу измерения через «Сервис- Параметры- LibreOffice Writer- Общие»