Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 7010|回复: 10

[已解决][求助]如何删除右键菜单按钮

[复制链接]
发表于 2009-9-28 12:39 | 显示全部楼层 |阅读模式

1\添加右键菜单可用下面代码

Sub 添加右键菜单()
On Error Resume Next
Application.CommandBars("cell").Controls("我的菜单").Delete
Dim mc As CommandBarControl
Set mc = Application.CommandBars("cell").Controls.Add
mc.Caption = "我的采单"
mc.OnAction = "aa"
MsgBox "完成"
End Sub

2\用下面的代码不能删除右键菜单按钮

Sub 删除右键菜单()
On Error Resume Next
Application.CommandBars("cell").Controls("我的菜单").Delete
MsgBox "已删除"
End Sub

请教删除右键菜单按钮的代码如何写谢谢!

最佳答案
2009-9-28 12:51
Sub 删除右键菜单()
On Error Resume Next
Dim mc As CommandBarControl
For Each mc In Application.CommandBars("cell").Controls
    If mc.Caption = "我的采单" Then mc.Delete
Next
MsgBox "已删除"
End Sub
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2009-9-28 12:47 | 显示全部楼层

Sub 删除右键菜单()
On Error Resume Next
Application.CommandBars("cell").Reset
MsgBox "已删除"
End Sub
回复

使用道具 举报

发表于 2009-9-28 12:51 | 显示全部楼层    本楼为最佳答案   

Sub 删除右键菜单()
On Error Resume Next
Dim mc As CommandBarControl
For Each mc In Application.CommandBars("cell").Controls
    If mc.Caption = "我的采单" Then mc.Delete
Next
MsgBox "已删除"
End Sub
回复

使用道具 举报

 楼主| 发表于 2009-9-28 12:54 | 显示全部楼层

用阿木前个代码,删除用户全部添加的菜单按钮.

如果要删除其中一个就不行了.

回复

使用道具 举报

发表于 2009-9-28 12:55 | 显示全部楼层

学习学习
回复

使用道具 举报

 楼主| 发表于 2009-9-28 12:59 | 显示全部楼层

请问:为什么这个代码就不行呢.

Sub 删除右键菜单()
On Error Resume Next
Application.CommandBars("cell").Controls("我的菜单").Delete
MsgBox "已删除"
End Sub

回复

使用道具 举报

 楼主| 发表于 2009-9-28 13:05 | 显示全部楼层

难道是书本有错?
回复

使用道具 举报

发表于 2009-9-28 13:15 | 显示全部楼层

汗,我想怎么不行。楼主写错一个字。

Sub 添加右键菜单()
On Error Resume Next
Application.CommandBars("cell").Controls("我的菜单").Delete
Dim mc As CommandBarControl
Set mc = Application.CommandBars("cell").Controls.Add
mc.Caption = "我的单"
mc.OnAction = "aa"
MsgBox "完成"
End Sub


Sub 删除右键菜单()
On Error Resume Next
Application.CommandBars("cell").Controls("我的菜单").Delete
MsgBox "已删除"
End Sub

回复

使用道具 举报

发表于 2009-9-28 13:17 | 显示全部楼层

哈哈 原来是楼主自己粗心

回复

使用道具 举报

 楼主| 发表于 2009-9-28 13:40 | 显示全部楼层

呀呀,真是的,是自已写错了字.

难怪,忙了一个早上怎么也不行

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-6-3 12:33 , Processed in 0.292493 second(s), 4 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表