- 帖子
- 5923
- 主題
- 13
- 精華
- 1
- 積分
- 5986
- 點名
- 0
- 作業系統
- win10
- 軟體版本
- Office 2010
- 閱讀權限
- 150
- 性別
- 男
- 來自
- 台灣基隆
- 註冊時間
- 2010-5-1
- 最後登錄
- 2022-1-23
        
|
4#
發表於 2013-5-21 17:38
| 只看該作者
回復 3# Scott090
FindControl(ID:=1561).execute 1561找不到,會是2010的ID不同??
這ID是應用程式自行建立的編碼.
(我用2003)
- Option Explicit
- Sub CommandBar_ID()
- Dim C As CommandBar, W As CommandBarControl, E As CommandBarControl, xl_Id As Integer
- On Error Resume Next
- For Each C In Application.CommandBars
- For Each W In C.Controls
- For Each E In W.Controls
- If E.Caption Like "檢視程式碼*" Then xl_Id = E.ID
- Next
- Next
- Next
- 設定引用項目 xl_Id
- End Sub
- Private Sub 設定引用項目(Bar_ID) '遺漏項存在時用手動刪除,用手動存檔後重新執行程式.
- Dim E
- On Error Resume Next
- With ThisWorkbook.VBProject
- For Each E In .References
- Debug.Print E.Name
- Next
- End With
- If Err <> 0 Then
- Application.CommandBars.FindControl(ID:=Bar_ID).Execute
- Application.SendKeys "%T"
- Application.SendKeys "R"
- End
- End If
- End Sub
複製代碼 |
|