将宏添加到右键菜单 [英] Add a macro to the right-button menu

查看:174
本文介绍了将宏添加到右键菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个创建的宏添加到右键菜单中。有可能吗?

I would like to add a created macro to the right-button menu. Is it possible?

非常感谢!

推荐答案

如果你意味着在您右键单击鼠标时向选项添加一个宏,然后您可以尝试此代码 CreateMacro ,将 Test_Macro 分配给带有标题的右键菜单 YourCode

If you meant add a macro to the options when you right click you mouse then you could try this code CreateMacro which assigns Test_Macro to the right click menu with a caption YourCode.

运行 KillMacro 删除菜单项

Const strMacro = "YourCode"

Sub CreateMacro()
   Dim cBut
   Call KillMacro
   Set cBut = Application.CommandBars("Cell").Controls.Add(Temporary:=True)
   With cBut
       .Caption = strMacro
       .Style = msoButtonCaption
       .OnAction = "Test_Macro"
   End With
End Sub

Sub Test_Macro()
   MsgBox "I work"
End Sub

Sub KillMacro()
   On Error Resume Next
   Application.CommandBars("Cell").Controls(strMacro).Delete
End Sub

这篇关于将宏添加到右键菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆