2008-11-04 12 views

回答

3

要使一個工具欄,在onload事件,你會做這樣的事情:

Dim myBar As CommandBar, myButt As CommandBarControl 

'Delete the toolbar if it already exists' 
On Error Resume Next 
CommandBars("My Toolbar").Delete 
On Error Goto 0 

Set myBar = CommandBars.Add(Name:="My Toolbar", _ 
     Position:=msoBarFloating, Temporary:=True) 
myBar.Visible = True 

' Create a button with text on the bar and set some properties.' 
Set myButt = ComBar.Controls.Add(Type:=msoControlButton) 
With myButt 
    .Caption = "Macro1" 
    .Style = msoButtonCaption 
    .TooltipText = "Run Macro1" 
    .OnAction = "Macro1" 
End With 

' Create a button with an image on the bar and set some properties.' 
Set myButt = ComBar.Controls.Add(Type:=msoControlButton) 
With myButt 
    'the faceId line will let you choose an icon' 
    ' If you choose to use the faceId then the caption is not displayed' 
    .FaceId = 1000 
    .Caption = "Icon Button" 
    .TooltipText = "Run Macro2" 
    .OnAction = "Macro2" 
End With 

禮貌要做的是退出時刪除工具欄,也。

+0

@ BradC - 那裏有趣的變量名稱。 :-) – 2008-11-04 16:24:29

1

不知道這是你在找什麼,但是我想這可能幫助你:

Excel -- Macro Toolbar

既然你不指定版本的Excel我不知道,如果這會爲你工作或不工作,但也許它會爲你提供一個很好的起點。

+0

謝謝... Excel 2003,但它也應該在2007年。 – Jason 2008-11-04 16:21:59

相關問題