2,463
社区成员
发帖
与我相关
我的任务
分享
'使用代码安装‘笔’工具栏
'以下示例创建了包含一个命令按钮的命令栏。通过 CommandBarButton 对象的 OnAction 属性,
'可用 CopyFace 方法将内置的“打开”按钮的按钮图符复制到“剪贴板”上,再用 PasteFace
'方法将其粘贴到已存在的按钮上。这样就在运行时间修改了命令栏按钮的外观。
Sub testAddModifyToolbars1()
Set myBar = CommandBars.Add(Name:="ChangingButton", Position:=msoBarTop, Temporary:=True)
myBar.Visible = True
Set oldControl = myBar.Controls.Add(Type:=msoControlButton, ID:=CommandBars("Standard").Controls("Copy").Id)
oldControl.OnAction = "changeFaces"
End Sub
Sub changeFaces()
Set newControl = CommandBars.FindControl(Type:=msoControlButton, ID:=CommandBars("Standard").Controls("Paste").Id)
newControl.CopyFace
Set oldControl = CommandBars("ChangingButton").Controls(1)
oldControl.PasteFace
End Sub