返回列表 上一主題 發帖

[發問] Excel VBE commandBar control ID 碼的列表

回復 1# Scott090
  1. Option Explicit
  2. Sub CommandBar_Id()
  3.     Dim C As CommandBar, W As CommandBarControl, E As CommandBarControl, I As Integer
  4.     On Error Resume Next
  5.     For Each C In Application.CommandBars
  6.         For Each W In C.Controls
  7.             For Each E In W.Controls
  8.                 Cells(I, "A") = E.Caption
  9.                 Cells(I, "B") = E.ID
  10.                 I = I + 1
  11.             Next
  12.         Next
  13.     Next
  14. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 3# Scott090
FindControl(ID:=1561).execute  1561找不到,會是2010的ID不同??
這ID是應用程式自行建立的編碼.

(我用2003)

  1. Option Explicit
  2. Sub CommandBar_ID()
  3.     Dim C As CommandBar, W As CommandBarControl, E As CommandBarControl, xl_Id As Integer
  4.     On Error Resume Next
  5.     For Each C In Application.CommandBars
  6.         For Each W In C.Controls
  7.             For Each E In W.Controls
  8.                 If E.Caption Like "檢視程式碼*" Then xl_Id = E.ID
  9.             Next
  10.         Next
  11.     Next
  12.     設定引用項目 xl_Id
  13. End Sub
  14. Private Sub 設定引用項目(Bar_ID)  '遺漏項存在時用手動刪除,用手動存檔後重新執行程式.
  15.     Dim E
  16.     On Error Resume Next
  17.     With ThisWorkbook.VBProject
  18.         For Each E In .References
  19.          Debug.Print E.Name
  20.         Next
  21.     End With
  22.     If Err <> 0 Then
  23.        Application.CommandBars.FindControl(ID:=Bar_ID).Execute
  24.        Application.SendKeys "%T"
  25.        Application.SendKeys "R"
  26.       End
  27.     End If
  28. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 5# Scott090
請執行 2#的程式


感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 太陽光大、父母恩大、君子量大,小人氣大。
返回列表 上一主題