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

suchen, ob Programm bereits geöffnet

suchen, ob Programm bereits geöffnet
02.09.2006 15:10:36
basti
Hallo,
wie kann ich möglichst einfach per Makro nachsehen, ob ein bestimmtes Programm (in meinem Fall Word) schon geöffnet ist? Ich hab zwar im Archiv schon gesucht und wurde auch fündig, allerdings bring ich keine der gefundenen Codes zum laufen.
Es wäre nett, wenn auch mit angegeben wird, wo ich diesen Code dann einbauen muss (ins Modul oder wohin?)
Vielen Dank schon mal für die Hilfe

7
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: suchen, ob Programm bereits geöffnet
02.09.2006 20:32:07
Josef
Hallo Basti!
Wenn es sich nur um Word handelt, dann gehts auch so.
Sub schonOffen()
Dim objWordApp As Object

On Error Resume Next

Set objWordApp = GetObject(, "Word.Application")

If Not objWordApp Is Nothing Then
  MsgBox "Word ist geöffnet!"
Else
  MsgBox "Word ist nicht geöffnet!"
End If

Set objWordApp = Nothing

Err.Clear
On Error GoTo 0
End Sub



Gruß Sepp

Anzeige
AW: suchen, ob Programm bereits geöffnet
03.09.2006 20:01:39
Basti
Hallo Sepp,
mit Word funktionierts einwandfrei! Vielen Danke!!
Hast du vielleicht noch eine Lösung, wie das mit WinZip hinhauen könnte? Habs schon mit allen möglichen Kombinationen probiert, aber er findets nicht!
Gruß, Basti
AW: suchen, ob Programm bereits geöffnet
03.09.2006 20:14:49
Josef
Hallo Basti!
Dann geht's nur mit dem Tipp von Beate per API.
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
  (ByVal lFlags As Long, ByVal lProcessID As Long) As Long

Private Declare Function ProcessFirst Lib "kernel32" Alias _
  "Process32First" (ByVal hSnapShot As Long, uProcess _
  As PROCESSENTRY32) As Long

Private Declare Function ProcessNext Lib "kernel32" Alias _
  "Process32Next" (ByVal hSnapShot As Long, uProcess _
  As PROCESSENTRY32) As Long

Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass _
  As Long)

Const TH32CS_SNAPPROCESS As Long = 2&
Const MAX_PATH As Integer = 260

Private Type PROCESSENTRY32
  dwSize As Long
  cntUsage As Long
  th32ProcessID As Long
  th32DefaultHeapID As Long
  th32ModuleID As Long
  cntThreads As Long
  th32ParentProcessID As Long
  pcPriClassBase As Long
  dwFlags As Long
  szExeFile As String * MAX_PATH
End Type


Private Function ProcessRunning(ByVal Processname As String) As Boolean
Dim hSnapShot As Long, Result As Long
Dim aa As String, bb As String
Dim Process As PROCESSENTRY32

hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot = 0 Then Exit Function

Process.dwSize = Len(Process)
Result = ProcessFirst(hSnapShot, Process)

Do While Result <> 0
  aa = Process.szExeFile
  
  aa = Left$(aa, InStr(aa, Chr$(0)) - 1)
  
  If LCase(aa) Like "*" & LCase(Processname) & "*" Then ProcessRunning = True: Exit Do
  
  Result = ProcessNext(hSnapShot, Process)
Loop

Call CloseHandle(hSnapShot)

End Function


Sub test()
MsgBox ProcessRunning("winzip")
End Sub


Gruß Sepp

Anzeige
besser so!
03.09.2006 20:19:51
Josef
Hallo nochmal,
nimm diese Version.
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" _
  (ByVal lFlags As Long, ByVal lProcessID As Long) As Long

Private Declare Function ProcessFirst Lib "kernel32" Alias _
  "Process32First" (ByVal hSnapShot As Long, uProcess _
  As PROCESSENTRY32) As Long

Private Declare Function ProcessNext Lib "kernel32" Alias _
  "Process32Next" (ByVal hSnapShot As Long, uProcess _
  As PROCESSENTRY32) As Long

Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass _
  As Long)

Const TH32CS_SNAPPROCESS As Long = 2&
Const MAX_PATH As Integer = 260

Private Type PROCESSENTRY32
  dwSize As Long
  cntUsage As Long
  th32ProcessID As Long
  th32DefaultHeapID As Long
  th32ModuleID As Long
  cntThreads As Long
  th32ParentProcessID As Long
  pcPriClassBase As Long
  dwFlags As Long
  szExeFile As String * MAX_PATH
End Type


Private Function ProcessRunning(ByVal Processname As String) As Boolean
Dim hSnapShot As Long, Result As Long
Dim aa As String, bb As String
Dim Process As PROCESSENTRY32

hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If hSnapShot = 0 Then Exit Function

Process.dwSize = Len(Process)
Result = ProcessFirst(hSnapShot, Process)

Do While Result <> 0
  aa = Process.szExeFile
  
  aa = Left$(aa, InStr(aa, Chr$(0)) - 1)
  
  If Right$(LCase(aa), 4) = ".exe" Then
    
    If LCase(aa) Like "*" & LCase(Processname) & "*" Then ProcessRunning = True: Exit Do
    
  End If
  
  Result = ProcessNext(hSnapShot, Process)
Loop

Call CloseHandle(hSnapShot)

End Function


Sub test()
MsgBox ProcessRunning("winzip")
End Sub


Gruß Sepp

Anzeige
AW: suchen, ob Programm bereits geöffnet
03.09.2006 20:25:46
Basti
Hallo Sepp,
vielen Dank für die schnelle und gute Hilfe!! Jetzt läufts wunderbar.
Gruß, Basti
AW: suchen, ob Programm bereits geöffnet
03.09.2006 20:38:30
Basti
Natürlich möcht ich mich auch noch bei Beate bedanken!!

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige