gpt4 book ai didi

excel - VBA|VSTO|仅适用于图片/对象的 CommandBar ContextMenu

转载 作者:行者123 更新时间:2023-12-04 20:11:30 25 4
gpt4 key购买 nike

我需要帮助将上下文菜单项 ( CommandBar ) 添加到我的应用程序:

将限制实际控件仅填充图片和形状的东西:

Public WithEvents ContextMenuItem_SaveAsPicture As Office.CommandBarButton
Dim ContextMenu As Office.CommandBar = Application.CommandBars("Pictures&Objects")

枚举我的应用程序中的所有 CommandBars 产生:
Worksheet Menu Bar
Chart Menu Bar
WordArt
Picture
Drawing Canvas
Organization Chart
Diagram
Ink Drawing and Writing
Ink Annotations
Circular Reference
Standard
Formatting
PivotTable
Chart
Reviewing
Forms
Stop Recording
External Data
Formula Auditing
Full Screen
PivotChart Menu
Visual Basic
Web
Control Toolbox
Exit Design Mode
Refresh
Watch Window
PivotTable Field List
Workbook Queries
Data Catalog Search
Shared Queries
Borders
Protection
Text To Speech
List
Compare Side by Side
Workbook tabs
Cell
Column
Row
Cell
Column
Row
Ply
XLM Cell
Document
Desktop
Nondefault Drag and Drop
AutoFill
Button
Dialog
Series
Plot Area
Floor and Walls
Trendline
Chart
Format Data Series
Format Axis
Format Legend Entry
Formula Bar
PivotTable Context Menu
Query
Query Layout
AutoCalculate
Object/Plot
Title Bar (Charting)
Layout
Pivot Chart Popup
Phonetic Information
Auto Sum
Paste Special Dropdown
Find Format
Replace Format
List Range Popup
List Range Layout Popup
XML Range Popup
List Range Layout Popup
Nil
Filter Names
Excel Previewer
&Legacy Keyboard Support
Row
Column
Drawing
Shadow Settings
3-D Settings
Borders
Borders
Draw Border
Chart Type
Pattern
Font Color
Fill Color
Line Color
Drawing and Writing Pens
Annotation Pens
Drawing and Writing Pens
Annotation Pens
Order
Nudge
Align or Distribute
Rotate or Flip
Lines
Connectors
AutoShapes
Callouts
Flowchart
Block Arrows
Stars & Banners
Basic Shapes
Insert Shape
Shapes
Inactive Chart
Excel Control
Curve
Curve Node
Curve Segment
Pictures Context Menu
OLE Object
ActiveX Control
WordArt Context Menu
Rotate Mode
Connector
Script Anchor Popup
Canvas Popup
Organization Chart Popup
Diagram
Layout
Select
FaceID Browser
Custom 1
History
Task Pane

Property Editor
Office Clipboard
XML Source
Research
XML Document
Signatures
Document Actions
Clip Art
Selection
Format Object
Document Management
Document Updates
Mail Merge Panes
Fax Service
Meeting Workspace
Attachment Options
Accessibility Checker
Editor
Dictionaries
Thesaurus
Share
Smart Lookup
Activity
Researcher
Tap
Help
Online Content
Alt Text
Changes
Ribbon Adapter
Add Command
Built-in Menus
Clipboard
Envelope

Team
Status Bar
Ribbon

到目前为止,像“形状”或“图片上下文菜单”或“图片”甚至“基本形状”这样的引人注目的东西都不会产生任何结果,甚至不会产生错误。

如果有帮助,这是我添加它的方法:
 ContextMenuItem_SaveAsPicture = ContextMenu.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Before:=1, Temporary:=False)

唯一对我有用的是美妙的 'Cell'List Range Popup , 对于表格,CommandBars

我想我会通过耗时 1 来进行良好的 ole 试验和错误 1,但在 SO 上没有看到这个,所以我想我会问一下,以防你们中的一个聪明人在我尝试 #100 之前得到答案

最佳答案

虽然这可以在运行时完成,但我发现它 广泛更容易走 XML 途径,因为这正是微软真正希望你做的事情,而且我已经设置了功能区并没有什么坏处。

我发现这些 CommandBar id/名称都不是最新的,而且大多数都已过时,因为我假设它们中的大多数只是 FluentUI Excel 之前版本的占位符。

如果您在这里使用 XML 是一个不完整的示例,仅用于为图片/形状填充项目,但当然可以使用下面提到的标识符进行更改以满足您的需要:

<!-- language: lang-xml -->
....
<contextMenus>

<!--Handles Pictures-->
<contextMenu idMso="ContextMenuPicture">
<button id="ContextMenu_SaveAsPicture2" label="Save As Picture" imageMso="WebControlSubmitWithImage" onAction="onAction"/>
</contextMenu>

<!--Handles Shapes : Basic, Block, Flowcharts and otherwise-->
<contextMenu idMso="ContextMenuShape">
<button id="ContextMenu_SaveAsPicture" label="Save As Picture" imageMso="WebControlSubmitWithImage" onAction="onAction"/>
</contextMenu>

<!--Handles when you group shapes, applies to pictures as well, or a mix of both-->
<contextMenu idMso="ContextMenuObjectsGroup">
<button id="ContextMenu_SaveAsPicture3" label="Save As Picture" imageMso="WebControlSubmitWithImage" onAction="onAction"/>
</contextMenu>

<!--Handles Line Shapes and line segments-->
<contextMenu idMso="ContextMenuShapeConnector">
<button id="ContextMenu_SaveAsPicture4" label="Save As Picture" imageMso="WebControlSubmitWithImage" onAction="onAction"/>
</contextMenu>

<!--Handles Freefrom drawn shapes -->
<contextMenu idMso="ContextMenuShapeFreeform">
<button id="ContextMenu_SaveAsPicture5" label="Save As Picture" imageMso="WebControlSubmitWithImage" onAction="onAction"/>
</contextMenu>
</contextMenus>
....

此外,在 MSDN 上进行了一些认真的挖掘之后,我偶然发现了一个很棒的、非常彻底的标记标识符 PDF,适用于所有情况,不仅限于这个问题。这在尝试在某些 idMso 之前或之后插入时很有用也不知道叫什么。我真的很想使用 ContextualTabs,但以前很难找到标识符。认为这会帮助其他人搜索功能区标识符,但这对我个人来说是一个很好的发现。

这是来自微软下载门户的直接链接: [MSDN-CUICT/Excel]

它以 .txt 格式下载,但为了便于阅读,我将其导出到 Excel 中。无论如何,快速的 CTRL+F 将帮助您导航到任何标识符/类别。它甚至列出了每个标识符支持的 Excel 版本

在链接失效的情况下,发现导航到:
[MS-CUSTOMUI2]: Custom UI XML Markup Version 2 Specification > 然后转到最近的日期 > 单击 CT_ContextMenu 的超链接,而不是 CT_ContextMenus > 并在 idMso 描述中单击它们提供的任何部分超链接引用 > 然后单击 Excel 命令表链接

关于excel - VBA|VSTO|仅适用于图片/对象的 CommandBar ContextMenu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42443120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com