DEAR SIR
之前研讀前輩之大作 引用說明如下
1.先抓 ID
Sub Id()
Sheet1.[A1:IV65536].ClearContents
For Each cmd In CommandBars
Cells(i + j + 2, 1) = cmd.Index
Cells(i + j + 2, 2) = cmd.Name
Cells(i + j + 2, 3) = cmd.Position
Cells(i + j + 2, 4) = cmd.Type
For Each ctl In CommandBars(cmd.Name).Controls
Cells(i + j + 2, 5) = ctl.Id
Cells(i + j + 2, 6) = ctl.Caption
j = j + 1
Next ctl
i = i + 1
Next
End Sub
2.依需求執行 隱藏 或 使用
Sub disPaste()
Dim i As Integer
Dim PasteCtls As CommandBarControls
Dim PasteCtl As CommandBarControl
'尋找所有 [複製] 按鈕, 其ID為19
'尋找所有 [剪下] 按鈕, 其ID為23
'尋找所有 [貼上] 按鈕, 其ID為22
Set PasteCtls = Application.CommandBars.FindControls(Id:=848) ' 選取所需之ID-羅
'將所有 [複製] 按鈕功能取消
i = 0
Debug.Print PasteCtls.Count
For Each PasteCtl In PasteCtls
i = i + 1
Debug.Print i
PasteCtl.Enabled = True 'TRUE即可回覆-羅
Next
'取消 [複製] 快捷鍵
Application.OnKey "^v", ""
'工作表標籤右鍵所跳出來的 "ply" 工具列"移動或複製(M)..." 按鈕可移動並產生副本
'因此一并禁止
Application.CommandBars("ply").Controls(5).Enabled = True 'TRUE即可回覆-羅
'以上應該就無法複製了
End Sub作者: dindon 時間: 2014-11-28 13:13