Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
760to764
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
760to764
760to764
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Fensterhandle

Fensterhandle
05.05.2006 21:28:39
Udo
Hi,
kann man vielleicht mit API das Fensterhandle der Exceltabelle auslesen,
nicht das der Application? Wenn ja, wie gehts?
Grüße Udo

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Fensterhandle
05.05.2006 22:31:53
Nepumuk
Hallo Udo,
so:
Option Explicit

Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" ( _
    ByVal hWnd As Long, _
    ByVal lpString As String, _
    ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" ( _
    ByVal hWnd As Long) As Long
Public Declare Function EnumChildWindows Lib "user32.dll" ( _
    ByVal hwndParent As Long, _
    ByVal lpEnumFunc As Long, _
    ByVal lParam As Any) As Long
Private Declare Function EnumWindows Lib "user32.dll" ( _
    ByVal lpEnumFunc As Long, _
    ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" ( _
    ByVal hWnd As Long, _
    ByVal lpClassName As String, _
    ByVal nMaxCount As Long) As Long

Private Const GC_CLASSNAMEMSEXCEL = "XLMAIN"
Private Const GC_CLASSNAMEMSEXCELFILE = "EXCEL7"
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD

Public Sub prcEnumThem()
    EnumWindows AddressOf EnumWindow, ByVal 0&
End Sub

Private Function EnumWindow(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
    Dim strClassname As String * 100
    GetClassName hWnd, strClassname, 100
    If Left$(strClassname, Len(GC_CLASSNAMEMSEXCEL)) = GC_CLASSNAMEMSEXCEL Then
        EnumChildWindows hWnd, AddressOf EnumChildWindow, 0&
        Exit Function
    End If
    EnumWindow = 1
End Function

Private Function EnumChildWindow(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
    Dim strClassname As String * 100
    GetClassName hWnd, strClassname, 100
    If Left$(strClassname, Len(GC_CLASSNAMEMSEXCELFILE)) = GC_CLASSNAMEMSEXCELFILE Then
        If GetText(hWnd) = ThisWorkbook.Name Then Debug.Print hWnd
        Exit Function
    End If
    EnumChildWindow = 1
End Function

Private Function GetText(hWnd As Long) As String
    Dim strText As String
    strText = String(GetWindowTextLength(hWnd) + 1, Chr$(0))
    GetWindowText hWnd, strText, Len(strText)
    GetText = Left$(strText, InStr(strText, Chr$(0)) - 1)
End Function

Gruß
Nepumuk

Anzeige
AW: Fensterhandle
05.05.2006 22:44:21
Udo
Hi,
danke, was genau wird denn da ausgelesen? Ich erhalte bei jedem Blatt den selben Wert,
müssten das nicht für jedes Blatt unterschiedliche Werte sein?
Grüße Udo
vergessen, offen oT
05.05.2006 23:02:40
Udo
o
AW: Fensterhandle
05.05.2006 23:09:27
Nepumuk
Hi,
das ist klar, die Tabellen werden immer in selben Fenster angezeigt. Nur wenn du über Fenster - Neues Fenster unterschiedliche Tabellen anzeigst, dann haben die eine eigene Zugriffsnummer. Du kannst aber nicht auslesen, welche Tabelle es ist, sondern nur, welches Fenster. Also z.B. Mappe1.xls:1 - Mappe1.xls:2 so, wie es auch in der Taskleiste angezeigt wird.
Gruß
Nepumuk

Anzeige
Klar, danke oT
05.05.2006 23:13:15
Udo
oT

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige