Anzeige
Archiv - Navigation
656to660
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
656to660
656to660
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Mehrere Excelinstanzen

Mehrere Excelinstanzen
29.08.2005 12:07:16
Alexej
Hallo Forum :)
Meine Frage waere: Ist es moeglich, mehrere Excelinstanzen aus einem Exceldokument zu ueberpruefen? Ich habe z.B. 4 Dokumente offen, jeder in seiner eigenen Excelinstanz (d.h., ich kann die anderen Dokumente nicht von einem Dokument aus sehen). Wie waere es nun moeglich, von dem einem Dokument aus, alle anderen geoffnetet Exceldokumente zu ueberpruefen. z.B. was fuer ein Wert in der Zelle A1 auf dem ersten Arbeitsblatt des jeweilen Dokumentes ist.
Ist das ueberhaupt moeglich?
Schoene Gruesse,
Alexej

9
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Mehrere Excelinstanzen
29.08.2005 12:11:16
Fred
Hi,
kommt darauf an, wie die Instanzen erzeugt werden.
mfg Fred
AW: Mehrere Excelinstanzen
29.08.2005 12:22:57
Alexej
Hallo,
Indem z.B. eine weitere Excelanwendung gestartet wird und dort wird ein Dokument geoffnet. Jedenfalls ist dieses neue Dokument fuer mein "Suchdokument" nicht sichtbar.
Gruss,
Alexej
AW: Mehrere Excelinstanzen
29.08.2005 12:39:00
Fred
Hi,
"Indem z.B. eine weitere Excelanwendung gestartet wird"
Ja klar, aber wie wird die gestartet?
mfg Fred
AW: Mehrere Excelinstanzen
29.08.2005 12:44:53
Alexej
Hallo,
Verstehe die Frage nicht ganz.
Nehmen wir an, es sind z.Z. 5 Exceldokumente geoeffnet.
3 von dennen wurden mit einem Doppelklick auf das jeweile Dokument in Windows geoeffnet.
2 weitere wurden geoffnet, indem eine Excelanwendung gestartet wurde (ueber eine Verknuepfung auf dem Desktop oder Startmenue) und in der Anwendung wurde ueber die Option "oeffnen" das jeweilige Dokument geoeffnet.
Dadurch habe ich jetzt 3 unabhaengige Excelanwendungen.
MfG,
Alexej
Anzeige
AW: Mehrere Excelinstanzen
29.08.2005 12:49:34
Fred
Hi,
das ist nicht nachvollziehbar. Wenn ich mehrere Datein aus dem Explorer durch Doppelklick öffne, landen die alle in einer Instanz.
mfg Fred
AW: Mehrere Excelinstanzen
29.08.2005 13:25:10
Nepumuk
Hi,
dazu musst du die Fenstertitel der Excelinstanzen auslesen. Wenn du die die aber per Makro geändert hast (ActiveWindow.Caption = "IRGENDWAS"), dann hast du schlechte Karten. Ein Beispielcode. Die anderen Instanzen sind im Array "objApplication"
' **********************************************************************
' Modul: Modul5 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

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
Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" ( _
    ByVal hwnd As Long, _
    ByVal lpClassName As String, _
    ByVal nMaxCount As Long) As Long

Private Const GW_HWNDFIRST = 0&
Private Const GW_HWNDNEXT = 2&
Private Const GWL_STYLE = -16&
Private Const WS_VISIBLE = &H10000000
Private Const WS_BORDER = &H800000
Private Const gcClassnameMSExcel = "XLMAIN"

Private objApplication() As Object

Public Sub GetWindowList()
    Dim hwnd As Long, sTitle As String, lStyle As Long
    Dim lpClassName As String, lReturn As Long
    Dim iCount As Integer
    lpClassName = Space(256)
    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) And Trim$(sTitle) <> "" Then
            lReturn = GetClassName(hwnd, lpClassName, 256)
            If Left$(lpClassName, lReturn) = gcClassnameMSExcel Then
                If sTitle <> Application.Caption Then
                    iCount = iCount + 1
                    Redim Preserve objApplication(1 To iCount)
                    Set objApplication(iCount) = GetObject(Trim$(Split(sTitle, "-")(1)))
                End If
            End If
        End If
        hwnd = GetWindow(hwnd, GW_HWNDNEXT)
    Loop Until hwnd = 0
End Sub

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

Gruß
Nepumuk
Excel & VBA – Beispiele
Anzeige
AW: Mehrere Excelinstanzen
29.08.2005 13:50:12
Alexej
Hallo Nepumuk,
Danke sehr fuer den sehr ausfuehrlichen Code, ich glaube, das ist genau das, was ich brauche :)
Jedoch schimpft der bei der Ausfuehrung, dass die Funktion "GetWindow" nicht deklariert ist :(
Viele Gruesse,
Alexej Ratner
AW: Mehrere Excelinstanzen
29.08.2005 14:01:20
Nepumuk
Hi,
entschuldige, das Makro ist in einer Mappe, in der einige Funktionen als Public deklariert sind. So sollte es laufen:
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

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 GetClassName Lib "user32" Alias "GetClassNameA" ( _
    ByVal hwnd As Long, _
    ByVal lpClassName As String, _
    ByVal nMaxCount As Long) As Long

Private Const GW_HWNDFIRST = 0&
Private Const GW_HWNDNEXT = 2&
Private Const GWL_STYLE = -16&
Private Const WS_VISIBLE = &H10000000
Private Const WS_BORDER = &H800000
Private Const gcClassnameMSExcel = "XLMAIN"

Private objApplication() As Object

Public Sub GetWindowList()
    Dim hwnd As Long, sTitle As String, lStyle As Long
    Dim lpClassName As String, lReturn As Long
    Dim iCount As Integer
    lpClassName = Space(256)
    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) And Trim$(sTitle) <> "" Then
            lReturn = GetClassName(hwnd, lpClassName, 256)
            If Left$(lpClassName, lReturn) = gcClassnameMSExcel Then
                If sTitle <> Application.Caption Then
                    iCount = iCount + 1
                    Redim Preserve objApplication(1 To iCount)
                    Set objApplication(iCount) = GetObject(Trim$(Split(sTitle, "-")(1)))
                End If
            End If
        End If
        hwnd = GetWindow(hwnd, GW_HWNDNEXT)
    Loop Until hwnd = 0
End Sub

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

Gruß
Nepumuk
Excel & VBA – Beispiele
Anzeige
AW: Mehrere Excelinstanzen
29.08.2005 14:41:30
Alexej
Hallo Nepumuk,
Danke sehr fuer die Hilfe, das ist genau das, was ich brauche :)
Viele Gruesse,
Alexej

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige