Я понял, почему это не сработало.
- Откройте новую книгу, затем "Сохранить как" "RightClickMenu.xlam"
- Затем поместите ее сюда
C:\Users\USER\AppData\Roaming\Microsoft\AddIns\
- Выше на предлагаемом сайте 2 варианта " RightClickMenu ".Я решил использовать без dynamicMenu, потому что он работает быстрее.
- Откройте нашу книгу уже в Ribbon XML Editor ↵ или Custom UI Editor ↵ и вставьте XML-кодтам:
↴
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<contextMenus>
<contextMenu idMso="ContextMenuCell">
<menu
id="SubMenu1"
label="RightClickMenu"
insertBeforeMso="QuickAnalysis"
imageMso="AcceptAndAdvance">
<button idMso="Calculator"/>
<button idMso="MultiplicationSign"/>
<menuSeparator id="sep_1"/>
<menu
id="SubMenu2"
image="Hand"
label="Спец Примечание"
itemSize="large">
<button
id="MenuButton1"
label="Yellow"
imageMso="ColorYellow"
onAction="Special_NoteYellow"/>
<button
id="MenuButton2"
label="Teal"
imageMso="ColorTeal"
onAction="Special_NoteTeal"/>
</menu>
</menu>
<menuSeparator id="sep_2" insertBeforeMso="Cut"/>
</contextMenu>
</contextMenus>
</customUI>
5. Далее введите VBA-код
ALT +
F11 - это наши кнопки.Вы можете добавить столько кнопок, сколько хотите.DynamicMenu можно расширить, как вам нравится:
↴
Option Explicit
Sub Special_NoteYellow(control As IRibbonControl)
Dim myComm As Comment
If Not ActiveCell.Comment Is Nothing Then
If MsgBox("The cell already contains a note, delete?", 4) - 7 Then
ActiveCell.Comment.Delete
Else: Exit Sub
End If
End If
Set myComm = ActiveCell.AddComment
With myComm.Shape 'exhibiting the required format
.Height = 110
.Width = 200
.AutoShapeType = 1
.Fill.ForeColor.SchemeColor = 13
.Line.ForeColor.RGB = RGB(255, 0, 0)
.DrawingObject.Font.Name = "Consolas"
.DrawingObject.Font.FontStyle = "normal"
.DrawingObject.Font.Size = 10
End With
'emulate the choice of "Change note"
SendKeys "+{F2}"
End Sub
Sub Special_NoteTeal(control As IRibbonControl)
Dim myComm As Comment
If Not ActiveCell.Comment Is Nothing Then
If MsgBox("The cell already contains a note, delete?", 4) - 7 Then
ActiveCell.Comment.Delete
Else: Exit Sub
End If
End If
Set myComm = ActiveCell.AddComment
With myComm.Shape 'exhibiting the required format
.Height = 110
.Width = 200
.AutoShapeType = 1
.Fill.ForeColor.SchemeColor = 15
.Line.ForeColor.RGB = RGB(255, 0, 0)
.DrawingObject.Font.Name = "Consolas"
.DrawingObject.Font.FontStyle = "normal"
.DrawingObject.Font.Size = 10
End With
'emulate the choice of "Change note"
SendKeys "+{F2}"
End Sub
Внимание!Для сохранения изменений необходимо:
- надстройка
.xlam
«Сохранить как» .xlsm
. - Редактируйте то, что нам нужно (вставьте значки, кнопки, меню и т. Д.).
- Далее «Сохранить как»
.xlam
!
Теперь поговорим о вставке вашей иконки.Для меню мы можем изменить значок в
Ribbon XML Editor ↵ или
Custom UI Editor ↵.Используйте эту запись -
imageMso="HappyFace"
или мы можем вставить собственную иконку
image="Hand"
для staticMenu.Если мы используем код
DynamicMenu
, который описан выше, значок, который необходимо вставить в строку VBA
image="Hand"
.
PS - также для собственного меню мы можем использовать атрибуты:
↴
button
checkBox
control
dynamicMenu
gallery
menu
menuSeparator
splitButton
toggleButton
- Если нам понадобится включить
RightClickMenu
для нас во всех книгах: - Перейдите на вкладку разработчика> Надстройки Excel.
- Или ... Файл> Параметры> Надстройки> Управление> Надстройки Excel> Перейти ... (проверьте созданную нами надстройку, если вы поместили ее в другую папку - используйте кнопку «Обзор»).
excel vba