AW: Excel-Suchfenster mit Makro wieder schließe
22.08.2015 20:45:55
Mullit
Hallo Werner,
ok, ich würd's ja weiterhin mit der .Find-Methode machen, die kannst Du in einer kleinen UserForm mit nur einem CommandButton aufrufen, und dann selbst manipulieren:
' **********************************************************************
' Modul: UserForm1 Typ: Userform
' **********************************************************************
Option Explicit
Private Sub CommandButton1_MouseUp( _
ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
Call prcSearch
End Sub
Private Sub prcSearch()
Static sobjCell As Range
Static sstrFirstAddress As String
With ActiveSheet.Range("E:E")
If sobjCell Is Nothing Then
Set sobjCell = .Find(What:=ActiveSheet.Cells(ActiveSheet.Rows.Count, 5).End(xlUp).Offset(1, 0).Value, _
LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
If Not sobjCell Is Nothing Then
With sobjCell
sstrFirstAddress = .Address
.Select
End With
End If
Else
Set sobjCell = .FindNext(After:=sobjCell)
With sobjCell
If Not sobjCell Is Nothing And .Address <> sstrFirstAddress Then
.Select
Else
MsgBox "Suche beendet..."
Call Unload(Object:=Me)
End If
End With
End If
End With
End Sub
VBA/HTML - CodeConverter für Office-Foren
AddIn für Excel/Word 2000-2010 - komplett in VBA geschrieben von Lukas Mosimann
Projektbetreuung durch mumpel
Code erstellt und getestet in Office 14
Es geht aber im Prinzip auch mit Deinem Excel-Dialog, wenn Du Api's ins Spiel bringst.
Wenn die Api's sich in XL2013 genauso, wie in XL2010 verhalten und Du eine 32-Bit Version von Office hast, könnte das gehen:
' **********************************************************************
' Modul: Typ: Standardmodul
' **********************************************************************
Option Explicit
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function DestroyWindow Lib "user32.dll" ( _
ByVal hwnd As Long) As Long
Private Declare Function SetTimer Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Private Const GC_CLASSNAMEMSEXCELDIALOG As String = "bosa_sdm_XL9"
Private llngHwnd As Long
Public Sub test()
llngHwnd = FindWindow(GC_CLASSNAMEMSEXCELDIALOG, "Suchen und Ersetzen")
Call prcStartTimer
End Sub
Private Sub prcStartTimer()
Call SetTimer(Application.hwnd, 0&, 10&, AddressOf TimerProc)
End Sub
Private Sub prcStopTimer()
Call KillTimer(Application.hwnd, 0&)
End Sub
Private Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long)
On Error Resume Next
Call prcStopTimer
Call DestroyWindow(llngHwnd)
End Sub
VBA/HTML - CodeConverter für Office-Foren
AddIn für Excel/Word 2000-2010 - komplett in VBA geschrieben von Lukas Mosimann
Projektbetreuung durch mumpel
Code erstellt und getestet in Office 14
Gruß, Mullit