Handling Anweisung Explorer Fenster (VBA)
07.08.2023 19:08:03
volti
Hallo Betsy,
falls Du noch nicht weitergekommen sein solltest oder für andere Interessierte hier noch mal eine andere Version.
Du wolltest ja nicht den Dateitext einsetzen, sondern den Typ in der Combobox ändern. Das kann man jetzt mit dem nachfolgendem Codebeispiel machen.
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare PtrSafe Function SendMessageA Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal wMsg As Long, _
ByVal wParam As LongPtr, lParam As Any) As LongPtr
Private Declare PtrSafe Function GetDlgCtrlID Lib "user32" ( _
ByVal hWnd As LongPtr) As Long
Private Declare PtrSafe Function FindWindowA Lib "user32" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function FindWindowExA Lib "user32" ( _
ByVal hWnd1 As LongPtr, _
ByVal hWnd2 As LongPtr, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As LongPtr
Private Declare PtrSafe Function GetClassNameA Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function EnumChildWindows Lib "user32" ( _
ByVal hWndParent As LongPtr, ByVal lpEnumFunc As LongPtr, _
ByVal lParam As LongPtr) As Long
Private Const BM_CLICK As Long = &HF5
Private Const CB_SETCURSEL As Long = &H14E
Dim iZaehler As Long
Sub Test()
Dim hTypSave As LongPtr, hSpeichernDialogButton As LongPtr
If CATIAApp Is Nothing Then
Set CATIAApp = CreateObject("CATIA.Application")
End If
' Dateityp ändern/ auswählen
hTypSave = FindWindowA("#32770", "Speichern unter")
If hTypSave > 0 Then
iZaehler = 0
EnumChildWindows hTypSave, AddressOf EnumControls, 4 ' Welche Position = Dateityp soll ausgewählt werden?
' Datei speichern
While hSpeichernDialogButton = 0
hSpeichernDialogButton = FindWindowExA(hTypSave, 0, "Button", "&Speichern")
Wend
SendMessageA hSpeichernDialogButton, BM_CLICK, 0, 0
End If
Sleep 1000
End Sub
Private Function EnumControls(ByVal hChild As LongPtr, ByVal lParam As LongPtr) As Long
Dim sKlasse As String * 32
GetClassNameA hChild, sKlasse, 32 ' Klasse des Controls
If Left$(sKlasse, InStr(sKlasse, vbNullChar) - 1) = "Combobox" Then
iZaehler = iZaehler + 1
If iZaehler = 2 Then ' 1=Dateiname 2=Dateityp 3=Codierung
SendMessageA hChild, CB_SETCURSEL, lParam, 0
EnumControls = False: Exit Function
End If
End If
EnumControls = True
End Function
Diese Variante reagiert sobald ein Speichern-Dialog im Arbeitsspeicher auftaucht. Der Dialog muss demnach nicht im Vordergrund sein.
PS: Evtl. noch die Suchtexte ins Englische transferieren....
viele Grüße KH