Hallo,
ok, hier mal eine Kompaktlösung mit einer Msgbox, für solche zusätzlichen Buttonbeschriftungen und weitere Anpassungen mußt Dir dann aber das Erstellen einer Userform aneignen, das ist sinnvoller und einfacher...
' **********************************************************************
' Modul: DieseArbeitsmappe Typ: Klassenmodul der Arbeitsmappe
' **********************************************************************
Option Explicit
Private Sub Workbook_Open()
With Tabelle1
Call .Activate
Call .Cells(8, 4).Select '// D8
End With
End Sub
' **********************************************************************
' Modul: Tabelle1 Typ: Klassenmodul des Tabellenblattes
' **********************************************************************
Option Explicit
Private Sub Worksheet_Activate()
Call Cells(8, 4).Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
With Target
If .Address = "$D$8" Then _
If .Value <> vbNullString Then _
Call prcResetDate(probjTarget:=Target)
End With
End Sub
Private Sub prcResetDate(ByRef probjTarget As Range)
Dim objCell As Range
Set objCell = Tabelle2.Columns(2).Find(What:=probjTarget.Value, _
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
If Not objCell Is Nothing Then
With objCell
Call .Parent.Activate
Call .Select
Select Case fncMsgBoxCustom("Der Wert " & .Value & " wurde gefunden," & _
" möchten Sie das Datum in Spalte D ersetzen?", _
vbExclamation + vbYesNoCancel, "Wert gefunden!")
Case Is = vbYes
.Offset(0, 2).Value = Date
Call prcActivateSheet(prwksSheet:=Me)
Case Is = vbNo
Call prcActivateSheet(prwksSheet:=Me)
End Select
End With
Set objCell = Nothing
End If
End Sub
Private Sub prcActivateSheet(ByRef prwksSheet As Worksheet)
With prwksSheet
Call .Cells(8, 4).ClearContents
Call .Activate
End With
End Sub
' **********************************************************************
' Modul: Modul1 Typ: Standardmodul
' **********************************************************************
Option Explicit
Option Private Module
Private Declare Function GetCurrentThreadId Lib "kernel32.dll" () As Long
Private Declare Function SetDlgItemText Lib "user32.dll" Alias "SetDlgItemTextA" ( _
ByVal hDlg As Long, _
ByVal nIDDlgItem As Long, _
ByVal lpString As String) As Long
Private Declare Function SetWindowsHookEx Lib "user32.dll" Alias "SetWindowsHookExA" ( _
ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32.dll" ( _
ByVal hHook As Long) As Long
Private Const WH_CBT As Long = 5
Private Const HCBT_ACTIVATE As Long = 5
Private Const IDCANCEL As Long = 2
Private llngHhook As Long
Public Function fncMsgBoxCustom(ByVal pvstrMsgText As String, _
ByVal pvenmButtons As VbMsgBoxStyle, ByVal pvstrBoxTitle As String) As VbMsgBoxResult
llngHhook = SetWindowsHookEx(WH_CBT, _
AddressOf WndHookProc, 0&, GetCurrentThreadId)
fncMsgBoxCustom = MsgBox(pvstrMsgText, pvenmButtons, pvstrBoxTitle)
End Function
Private Function WndHookProc(ByVal pvlnguMsg As Long, _
ByVal pvlngwParam As Long, ByVal pvlnglParam As Long) As Long
If pvlnguMsg = HCBT_ACTIVATE Then
Call SetDlgItemText(pvlngwParam, IDCANCEL, "Gerät bearbeiten")
Call UnhookWindowsHookEx(llngHhook)
End If
WndHookProc = False
End Function
Gruß,
|