AW: Excel-Dialog "Suchen und Ersetzen"
22.03.2021 17:23:57
Nepumuk
Hallo Jürgen,
just for fun:
Option Explicit
Private Declare PtrSafe Function EnumWindows Lib "user32.dll" ( _
ByVal lpEnumFunc As LongPtr, _
ByVal lParam As LongPtr) As Long
Private Declare PtrSafe Function GetWindowTextA Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare PtrSafe Function GetWindowTextLengthA Lib "user32.dll" ( _
ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function GetClassNameA Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function PostMessageA Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal wMsg As Long, _
ByVal wParam As LongPtr, _
ByVal lParam As LongPtr) As Long
Private Const WM_CLOSE As Long = &H10
Private Const GC_CLASSNAMEDIALOG As String = "bosa_sdm_XL9"
Public Sub Ein()
Application.CommandBars.ExecuteMso "FindDialogExcel"
End Sub
Public Sub Aus()
Call EnumWindows(AddressOf WindowCallBack, ByVal 0)
Cells.Find ""
End Sub
Private Function WindowCallBack(ByVal lngptrHwnd As LongPtr, ByVal lngptrParam As LongPtr) As LongPtr
Dim strCaption As String, strClassName As String
Dim lngReturn As Long
strClassName = Space$(256)
lngReturn = GetClassNameA(lngptrHwnd, strClassName, 256)
If Left$(strClassName, lngReturn) = GC_CLASSNAMEDIALOG Then
lngReturn = GetWindowTextLengthA(lngptrHwnd)
strCaption = Space$(lngReturn)
Call GetWindowTextA(lngptrHwnd, strCaption, lngReturn + 1)
If strCaption = "Suchen und Ersetzen" Then
Call PostMessageA(lngptrHwnd, WM_CLOSE, 0, 0)
DoEvents
WindowCallBack = 0
Else
WindowCallBack = 1
End If
Else
WindowCallBack = 1
End If
End Function
Gruß
Nepumuk