返回列表 上一主題 發帖

[發問] onaction="Macro",macro有參數如何寫呀

回復 1# mhl9mhl9

是要問CommandBarButton.OnAction 的部分嗎?

TOP

回復 5# mhl9mhl9

參考看看
  1. Public Const B1 As String = "text-B1"
  2. Public Const B2 As String = "text-B2"
  3. Public Const B3 As String = "text-B3"

  4. Public Sub abc()
  5.     With Application.CommandBars.Add("測試", msoBarTop, , True)
  6.         .Visible = True
  7.         With .Controls.Add(Type:=msoControlPopup) '參數代入數字
  8.             .Caption = "測試1"
  9.             With .Controls.Add(Type:=msoControlButton)
  10.                 .Caption = "測試0"
  11.                 .OnAction = "text" '沒代入參數
  12.             End With
  13.             With .Controls.Add(Type:=msoControlButton)
  14.                 .Caption = "測試1-1"
  15.                 .OnAction = "'text 1'" '代入參數會在原本最外圍的雙引號裡面分別加單引號
  16.             End With
  17.             With .Controls.Add(Type:=msoControlButton)
  18.                 .Caption = "測試1-2"
  19.                 .OnAction = "'text 1,2'" '不同參數用逗號分開
  20.             End With
  21.             With .Controls.Add(Type:=msoControlButton)
  22.                 .Caption = "測試1-3"
  23.                 .OnAction = "'text 1,2,3'"
  24.             End With
  25.         End With
  26.         With .Controls.Add(Type:=msoControlPopup) '參數代入文字
  27.             .Caption = "測試2"
  28.             With .Controls.Add(Type:=msoControlButton)
  29.                 .Caption = "測試2-1"
  30.                 .OnAction = "'text ""B1""'" '文字左右側分別加上兩個雙引號
  31.             End With
  32.             With .Controls.Add(Type:=msoControlButton)
  33.                 .Caption = "測試2-2"
  34.                 .OnAction = "'text ""B1"",""B2""'"
  35.             End With
  36.             With .Controls.Add(Type:=msoControlButton)
  37.                 .Caption = "測試2-3"
  38.                 .OnAction = "'text ""B1"",""B2"",""B3""'"
  39.             End With
  40.         End With
  41.         With .Controls.Add(Type:=msoControlPopup) '參數代入變數
  42.             .Caption = "測試3"
  43.             With .Controls.Add(Type:=msoControlButton)
  44.                 .Caption = "測試3-1"
  45.                 .OnAction = "'text B1'"
  46.             End With
  47.             With .Controls.Add(Type:=msoControlButton)
  48.                 .Caption = "測試3-2"
  49.                 .OnAction = "'text B1,B2'"
  50.             End With
  51.             With .Controls.Add(Type:=msoControlButton)
  52.                 .Caption = "測試3-3"
  53.                 .OnAction = "'text B1,B2,B3'"
  54.             End With
  55.         End With
  56.     End With
  57. End Sub


  58. Public Sub text(Optional Arg1 = "A1", Optional Arg2 = "A2", Optional Arg3 = "A3")  '預設沒代入參數的預設值
  59. MsgBox Arg1 & Chr(10) & Chr(13) & Arg2 & Chr(10) & Chr(13) & Arg3
  60. End Sub
複製代碼

TOP

        靜思自在 : 知識要用心體會,才能變成自己的智慧。
返回列表 上一主題