Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking for an open app

Status
Not open for further replies.

ADoozer

Programmer
Dec 15, 2002
3,487
AU
Ok im pretty sure i cant find the answer in advanced search... so here goes:

im currently using: -

On Error Resume Next
Set objWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then
'word not open
Err.Clear
Set objWord = New Word.Application
End If

to check if word is currently open....

what i would like to do is check (without using the on error bit) by doing something like:-

if objword=nothing then
'create object

however this errors saying invalid use of blah blah blah!

can anyone point me in the right direction, i dont like using errors to direct my code!!

any help appreciated!
 
You can use:
if objword is nothing then
'create objword
end if


Hope this is what you were looking for.

Brian Vander Zanden
 
These codes are from Microsoft and so is most of the code:

Below are some class names of applications that are shipped with Windows:
Class Name Application
SciCalc CALC.EXE
CalWndMain CALENDAR.EXE
Cardfile CARDFILE.EXE
Clipboard CLIPBOARD.EXE
Clock CLOCK.EXE
CtlPanelClass CONTROL.EXE
XLMain EXCEL.EXE
Session MS-DOS.EXE
Notepad NOTEPAD.EXE
pbParent PBRUSH.EXE
Pif PIFEDIT.EXE
PrintManager PRINTMAN.EXE
Progman PROGMAN.EXE (Windows Program manager)
Recorder RECORDER.EXE
Reversi REVERSI.EXE
#32770 SETUP.EXE
Solitaire SOL.EXE
Terminal TERMINAL.EXE
WFS_Frame WINFILE.EXE
MW_WINHELP WINHELP.EXE
#32770 WINVER.EXE
OpusApp WINWORD.EXE
MSWRITE_MENU WRITE.EXE

Private Declare Function FindWindow Lib &quot;user32&quot; Alias _
&quot;FindWindowA&quot; (ByVal lpClassName As String, _
ByVal lpWindowName As Long) As Long

Private Declare Function SendMessage Lib &quot;user32&quot; Alias _
&quot;SendMessageA&quot; (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Dim WordRunning As Boolean

Private Sub Command1_Click()
WordRunning = False
DetectWord
If WordRunning = True Then
MsgBox &quot;Word is running!&quot;, vbInformation
Else
MsgBox &quot;Word is not running!&quot;, vbInformation
End If
End Sub
Sub DetectWord()
' Procedure dectects a running Word and registers it.
Const WM_USER = 1024
Dim hWnd As Long
' If Excel is running this API call returns its handle.
hWnd = FindWindow(&quot;OpusApp&quot;, 0)
If hWnd = 0 Then ' 0 means Word not running.
Exit Sub
Else
' Excel is running so use the SendMessage API
' function to enter it in the Running Object Table.
SendMessage hWnd, WM_USER + 18, 0, 0
WordRunning = True
End If
End Sub Swi
 
bvanderzanden: thats exactly what im after.

swi: thats a little over the top for what this app does (and im trying to avoid api where necessary) however it may come in handy in the future!

thanks all!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top