AW: Event für Zeile löschen
03.02.2008 21:22:06
Nepumuk
Hallo Joachim,
na dann, erst mal die ID's. Mit folgender Prozedur lassen sich alle auflisten. Das sieht zwar ein bisschen umständlich aus, aber wenn ich durch das Auflistungsobjekt der Controls einer Commandbar laufe, bekomme ich komischerweise nicht alle zurück.
Public Sub ID_List()
Dim lngIndex As Long, lngRow As Long
Dim objBar As CommandBar, objControl As CommandBarControl
lngRow = 1
Application.ScreenUpdating = False
Cells.Clear
For lngIndex = 1 To 31500
For Each objBar In Application.CommandBars
Set objControl = objBar.FindControl(ID:=lngIndex, Recursive:=True)
If Not objControl Is Nothing Then
lngRow = lngRow + 1
Cells(lngRow, 1) = objControl.ID
Cells(lngRow, 2) = objControl.Index
Cells(lngRow, 3) = Replace(objControl.Caption, "&", "")
Cells(lngRow, 4) = objControl.Type
If objControl.Type = 1 Then Cells(lngRow, 5) = objControl.FaceId
Cells(lngRow, 6) = objBar.Name
Cells(lngRow, 7) = objBar.NameLocal
Cells(lngRow, 8) = objBar.Index
End If
Next
Next
With Range("A1:H1")
.Value = Array("ID Control", "Index Control", "Caption Control", "Typ Control", "FaceId Control", "In Leiste engl.", "In Leiste deutsch", "Index Leiste")
.Font.Bold = True
.AutoFilter
End With
Columns.AutoFit
Application.ScreenUpdating = True
End Sub
Über die ID eines Controls kannst du nach ihm suchen. Das geht so:
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Private objInsertButtonClass As clsInsertButton
Public Sub Intialize_Class()
Dim objControls As CommandBarControls
Set objControls = CommandBars.FindControls(ID:=3183) '3183=Zellen einfügen
If Not objControls Is Nothing Then
Set objInsertButtonClass = New clsInsertButton
Set objInsertButtonClass.prpSetButton = objControls.Item(1)
End If
End Sub
Public Sub Terminate_Class()
Set objInsertButtonClass = Nothing
End Sub
Dazu benötigst du dann noch ein Klassenmodul mit dem Namen "clsInsertButton" und folgendem Code:
' **********************************************************************
' Modul: clsInsertButton Typ: Klassenmodul
' **********************************************************************
Option Explicit
Private WithEvents mobjButton As Office.CommandBarButton
Friend Property Set prpSetButton(objButton As Office.CommandBarButton)
Set mobjButton = objButton
End Property
Private Sub mobjButton_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox "Einfügen"
End Sub
An Stelle der MsgBox kommt natürlich dein Code. Wenn du die Variable "CancelDefault" in der Prozedur auf True setzt, wird die Standardroutine des Buttons nicht ausgeführt und du kannst sie durch eine eigene Routine ersetzen.
Gruß
Nepumuk