Board logo

標題: [發問] 在命令列中增加Control卻無法呈現 .Caption ? [打印本頁]

作者: yangjie    時間: 2014-7-14 17:59     標題: 在命令列中增加Control卻無法呈現 .Caption ?

本帖最後由 yangjie 於 2014-7-14 18:00 編輯

請教大大先進們
跑完下列 製出一個CommandBarControl在命令列中
卻無法呈現 .Caption = "回主選單"
求救
Sub MakeMenu1()
    Dim bar As CommandBarControl
    Dim NewMenu1 As CommandBarControl
    Dim MenuCount As Integer
    Dim i As Integer
    For Each bar In Application.CommandBars(1).Controls
          bar.Visible = False
    Next
    On Error Resume Next
          Application.CommandBars(1).Controls("回主選單").Delete
    On Error GoTo 0
    MenuCount = Application.CommandBars(1).Controls.Count
    Set NewMenu1 = Application.CommandBars(1).Controls.Add(Type:=msoControlButton, before:=MenuCount, Temporary:=True)
    With NewMenu1
          .Caption = "回主選單"
          .OnAction = "myForm1"
    End With
End Sub
錯誤在哪?
若欲再增加2個Controls 又如何增寫?
作者: GBKEE    時間: 2014-7-15 15:01

回復 1# yangjie
  1. Option Explicit
  2. Sub MakeMenu1()
  3.     Dim bar As CommandBarControl
  4.     Dim NewMenu1 As CommandBarControl   
  5.     Dim MenuCount As Integer
  6.     Dim i As Integer
  7.     For Each bar In Application.CommandBars(1).Controls
  8.           bar.Visible = False
  9.     Next
  10.     On Error Resume Next
  11.     Application.CommandBars(1).Controls("回主選單").Delete
  12.     On Error GoTo 0
  13.     MenuCount = Application.CommandBars(1).Controls.Count
  14.     Set NewMenu1 = Application.CommandBars(1).Controls.Add(Type:=msoControlPopup, before:=MenuCount, Temporary:=True)
  15.    'Set NewMenu1 = Application.CommandBars(1).Controls.Add(Type:=10, before:=MenuCount, Temporary:=True)
  16.     With NewMenu1
  17.           .Caption = "回主選單"
  18.         '  .OnAction = "myForm1"
  19.          With .Controls.Add(Type:=msoControlButton)
  20.                 .FaceId = 264
  21.                 .Caption = "回主選單 A"
  22.              .OnAction = "myForm1"
  23.          End With
  24.          With .Controls.Add(Type:=msoControlButton)
  25.             .FaceId = 207
  26.             .Caption = "回主選單 B"
  27.              .OnAction = "myForm1"
  28.          End With
  29.     End With
  30. End Sub
複製代碼

作者: yangjie    時間: 2014-7-15 23:05

回復 2# GBKEE
謝謝GBKEE版大
.FaceId = 264
.FaceId = 207
是何意?請指導
作者: yangjie    時間: 2014-7-16 01:20

回復 3# yangjie
.FaceID=264  我知道了
但如何知道其他圖示的ID?




歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)