简体   繁体   English

VSTO C#/VBA 如何在上下文菜单 MS Project 2016+ 中添加我的菜单项

[英]VSTO C#/VBA how add my menu item in context menu MS Project 2016+

Need to add your context menu to the MS Project 2016+ menu using C# or VBA and VSTO.需要使用 C# 或 VBA 和 VSTO 将上下文菜单添加到 MS Project 2016+ 菜单。 In TASK list.在任务列表中。 Does anyone know how to do this?有谁知道如何做到这一点? I rummaged through the entire Internet but still could not find how to do it in MS Project.我翻遍了整个互联网,但仍然无法在 MS Project 中找到如何做到这一点。

Methods for Word Excel Outlook not work in MS Project Word Excel Outlook 的方法在 MS Project 中不起作用

It will also be enough for me how to do it in VBA.对我来说如何在 VBA 中做到这一点也足够了。 I will translate to C #我将翻译成 C #

This code work for Excel need for ms project此代码适用于 Excel 需要 ms 项目

Sub aaa()

Set cbt = CommandBars("Cell").Controls.Add(Temporary:=True)

With cbt
    .Caption = ("mymacro")
    .Style = msoButtonCaption
End With
   
End Sub





an attempt to find the required element and iterate over all possible ones.试图找到所需的元素并遍历所有可能的元素。 My menu was not added to the menu.我的菜单没有添加到菜单中。

public Microsoft.Office.Interop.MSProject.Application app = new Microsoft.Office.Interop.MSProject.Application();

            for (int i = 1; i < app.Application.CommandBars.Count; i++)
            {
                try
                {
                    
                    var _ContextMenu = (CommandBarButton)app.Application.CommandBars[app.Application.CommandBars[i].Name].Controls.Add(Temporary: true);
                    _ContextMenu.Style = MsoButtonStyle.msoButtonCaption;
                    _ContextMenu.Caption = "Hello !!!";
                    _ContextMenu.FaceId = 356;
                    _ContextMenu.Tag = "HELLO_TAG";
                }
                catch { }
            }

What am I doing wrong?我究竟做错了什么?

Thanks谢谢

Command bars were deprecated and can't be used for customizing the MS Office applications UI any longer.命令栏已弃用,不能再用于自定义 MS Office 应用程序 UI。 See Customizing Context Menus in Office 2010 for more information.有关详细信息,请参阅自定义 Office 2010 中的上下文菜单

Instead, you need to use the Fluent UI (aka Ribbon UI) for customizing the MS Project UI (including context menus).相反,您需要使用 Fluent UI(又名 Ribbon UI)来自定义 MS Project UI(包括上下文菜单)。 You can read more about the Fluent UI in the following articles:您可以在以下文章中阅读有关 Fluent UI 的更多信息:

Moreover, to get this working in MS Project you need to develop a COM based add-in implementing the IDTExtensibility2 interface.此外,要使其在 MS Project 中工作,您需要开发一个基于 COM 的插件,实现IDTExtensibility2接口。 Or just create a VSTO based add-in in Visual Studio in C# or VB.NET.或者只是在 C# 或 VB.NET 的 Visual Studio 中创建一个基于 VSTO 的加载项。 See Walkthrough: Create your first VSTO Add-in for Project for more information.有关详细信息,请参阅演练:为项目创建您的第一个 VSTO 外接程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM