AW: CommandBarButton mit Bild aus ImageList
18.09.2006 18:15:44
Egon
hi
Public
Sub NewPictureOnNewCommandBar()
' Zweck: Fügt ein Bild einer Schaltfläche der Befehlsleiste hinzu.
Dim objCommandBar As Office.CommandBar
Dim objCommandBarButton As Office.CommandBarButton
Dim objPicture As stdole.IPictureDisp
' Die nächste Codezeile auskommentieren, wenn Sie kein transparentes Bild einfügen möchten.
Dim objMask As stdole.IPictureDisp
Const PICTURE_PATH As String = "C:\Eigene Bilder\OK.bmp"
' Die nächste Codezeile auskommentieren, wenn Sie kein transparentes Bild einfügen möchten.
Const PICTURE_MASK As String = "C:\Eigene Bilder\OKMask.bmp"
Const COMMAND_BAR_NAME As String = "Befehlsleiste testen"
' Die nächste Zeile ersetzen durch:
' For Each objCommandBar In Application.ActiveExplorer.CommandBars <- Für Outlook
' For Each objCommandBar In Application.VBE.CommandBars <- Für Visual Basic-Editor
For Each objCommandBar In Application.CommandBars
If objCommandBar.Name = COMMAND_BAR_NAME Then
objCommandBar.Delete
End If
Next objCommandBar
Set objCommandBar = Application.CommandBars.Add(COMMAND_BAR_NAME)
Set objCommandBarButton = _
objCommandBar.Controls.Add(msoControlButton)
Set objPicture = LoadPicture(PICTURE_PATH)
' Die nächste Codezeile auskommentieren, wenn Sie kein transparentes Bild einfügen möchten.
Set objMask = LoadPicture(PICTURE_MASK)
objCommandBarButton.Picture = objPicture
' Die nächste Codezeile auskommentieren, wenn Sie kein transparentes Bild einfügen möchten.
objCommandBarButton.Mask = objMask
End Sub