Live-Forum - Die aktuellen Beiträge
Datum
Titel
29.03.2024 13:14:12
28.03.2024 21:12:36
28.03.2024 18:31:49
Anzeige
Archiv - Navigation
336to340
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
336to340
336to340
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

2. Userform und Excel 97

2. Userform und Excel 97
14.11.2003 19:12:20
chris b.
Hallo Excel Profis,
habe ein Probelm mit userform, un dzwar habe ich folgende codes in meiner userform und diese funktionieren auch alle unter dem Betriebssystem XP und Office2000, mein Problem ist ich habe auch Excel (office) 97 und unter diesem Code FUNKTIONIERT eine sache nicht und ich hoffe ihr könnt mir weiterhelfen.
Mit meinem Prog kann ich fremde Fenster z.B editor,, usw.. in den Vordergrund setzen und es so feststellen das dieses fenster immer aktiv bleibt das ganze sol auch mit der Userform selbst so sein als sie soll sich von keinem anderem Fenster ausbelnden lassen.. Das ganze funktioniert auch wunderbar unter Excel 2000 aber unter 97 und win2000 geht es nicht..? Ich hoffe ihr habe eine Lösung für mich ,
vielen Dank schon einmal gruß Christian

Es folgen 2 Codes
1 aus Userform und
1 aus Modul

Userform Code:

Public x1 As String
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const GWL_STYLE = (-16)
Const WS_VISIBLE = &H10000000
Const WS_BORDER = &H800000
Dim m1
Public cb As String
Dim whandle



Private Function GetWindowTitle(ByVal hWnd As Long) As String
Dim lResult As Long, sTemp As String
lResult = GetWindowTextLength(hWnd) + 1
sTemp = Space(lResult)
lResult = GetWindowText(hWnd, sTemp, lResult)
GetWindowTitle = Left(sTemp, Len(sTemp) - 1)
End Function





Private Sub ok_Click()
cb = ComboBox1.Value
Cells(1, 1) = cb
If OptionButton1.Value = True Then Call vordergrund
If OptionButton2.Value = True Then Call hintergrund
Label1.Caption = "Fertig"
NeueStunde = Hour(Now())
NeueMinute = Minute(Now())
NeueSekunde = Second(Now()) + 1
WarteZeit = TimeSerial(NeueStunde, NeueMinute, NeueSekunde)
Application.Wait WarteZeit
Label1.Caption = ""
End Sub





Private Sub abbrechen_Click()
Unload UserForm1
UserForm1.Hide
Application.Visible = True
End Sub





Private Sub akt_Click()
Unload UserForm1
UserForm1.Hide
Load UserForm1
UserForm1.Show
End Sub





Private Sub UserForm_Activate()
SetWindowPos FindWindow(vbNullString, Me.Caption), -2, 0, 0, 0, 0, 3
End Sub





Private Sub UserForm_Initialize()
Dim hWnd As Long, sTitle As String, lStyle As Long
hWnd = GetWindow(FindWindow(vbNullString, vbNullString), GW_HWNDFIRST)
Do
lStyle = GetWindowLong(hWnd, GWL_STYLE) And (WS_VISIBLE Or WS_BORDER)
sTitle = GetWindowTitle(hWnd)
If (lStyle = (WS_VISIBLE Or WS_BORDER)) = True And Trim(sTitle) <> "" Then
ComboBox1.AddItem sTitle
End If
hWnd = GetWindow(hWnd, GW_HWNDNEXT)
Loop Until hWnd = 0
End Sub



'-------------------------------------------------------------------
Code aus dem MODUL !!!

Declare Function GetWindow Lib "User32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowLong Lib "User32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal wIndx As Long) As Long
Declare Function GetWindowTextLength Lib "User32" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Declare Function GetWindowText Lib "User32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function SetWindowPos Lib "User32" (ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Sub vordergrund()
cb = Cells(1, 1)
whandle = FindWindow(vbNullString, cb)
Call SetWindowPos(whandle, -1, 0, 0, 0, 0, 3)
AppActivate (cb)
End Sub



Sub hintergrund()
cb = Cells(1, 1)
whandle = FindWindow(vbNullString, cb)
Call SetWindowPos(whandle, -2, 0, 0, 0, 0, 3)
End Sub

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: 2. Userform und Excel 97
14.11.2003 20:17:37
Nepumuk
Hallo chris,

1. Wird die Caption der Userform in der Combobox angezeigt?

2. Gib mal folgende Zeilen in das Klassenmodul der Userform ein und schreib mir, was angezeigt wird.


Private Sub UserForm_Activate()
MsgBox FindWindow(vbNullString, Me.Caption)
End Sub


Gruß
Nepumuk

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige