AW: Inhalt der Zelle in anderes Programm kopieren
16.10.2017 08:42:02
ChrisL
Hi
Folgende zwei Codes kombiniert:
http://foren.activevb.de/cgi-bin/foren/archivview.pl?forum=4&root=397781&msg=397803&id=#forum
https://www.herber.de/forum/archiv/1096to1100/1096012_AppActivate_dann_Fenster_in_Vordergrund.html
Benötigt:
1x Userform1
1x ListBox1
1x CommandButton1
Private Declare Function GetDesktopWindow Lib "user32" () _
As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd _
As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal wIndx As _
Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) _
As Long
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString _
As String, ByVal cch As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32.dll" ( _
ByVal hwnd As Long) As Long
Private Const GW_HwndFirst = 0
Private Const GW_HwndLast = 1
Private Const GW_HwndNext = 2
Private Const GW_HwndPrev = 3
Private Const GW_Owner = 4
Private Const GW_Child = 5
Private Const GW_Max = 5
Private Const GWL_Style = (-16)
Private Const WS_Visible = &H10000000
Private Const WS_Border = &H800000
Private Sub CommandButton1_Click()
Dim lngHwnd As Long
lngHwnd = FindWindow(vbNullString, ListBox1)
If lngHwnd 0 Then Call SetForegroundWindow(lngHwnd)
Application.SendKeys "^v"
End Sub
Private Sub UserForm_Initialize()
Dim hwnd As Long
Selection.Copy
' Erstes Child vom Desktop-Fenster für den Einstieg
hwnd = GetWindow(GetDesktopWindow, GW_Child)
' Alle vorhandenen Fenster abklappern
Do
Call GetWindowInfo(hwnd, Me.ListBox1)
hwnd = GetWindow(hwnd, GW_HwndNext)
Loop Until hwnd = 0
End Sub
Private Sub GetWindowInfo(ByVal hwnd&, lb As Control)
Dim Result&, Style&, Title$
' Darstellung des Fensters
Style = GetWindowLong(hwnd, GWL_Style)
Style = Style And (WS_Visible Or WS_Border)
' Titel des Fenster auslesen
Result = GetWindowTextLength(hwnd) + 1
Title = Space$(Result)
Result = GetWindowText(hwnd, Title, Result)
Title = Left$(Title, Len(Title) - 1)
If Title "" Then
If Style = (WS_Visible Or WS_Border) Then
lb.AddItem Title
End If
End If
End Sub
cu
Chris