|
-
Feb 17th, 2000, 12:45 PM
#1
Thread Starter
Fanatic Member
I have developed a small application, which works fine for the most part. The problem begins when it tries to open Word or Excel. If they are not already opened everything is fine, but if user opened Word or Excel (and of course didn't close them) before running my program it crashes basically (not everytime but usually it does). So here are my Q's:
1) how to check if Word or Excel is running. I know that I could look for window with specific caption (what I did actually), but how can I check if word or excel are in memory but are not visible?
2) how to close them once I know that they are running (through code of course).
I hope you get the idea of what I mean. Thanks in advance
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.
[This message has been edited by QWERTY (edited 02-18-2000).]
-
Feb 17th, 2000, 12:51 PM
#2
-
Feb 17th, 2000, 04:19 PM
#3
Lively Member
Hi,
I tried the following, and it worked pretty good:
Code:
Dim appObj As Object
On Error Resume Next
Set appObj = GetObject(, "Word.Application")
If Err Then
MsgBox "Word is not running"
Else
MsgBox "Word will be closed!"
appObj.Quit
End If
Replace "Word.Application" with "Excel.Application" for MS Excel.
Roger
-
Feb 17th, 2000, 09:26 PM
#4
Thread Starter
Fanatic Member
Thanks 
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.
[This message has been edited by QWERTY (edited 02-18-2000).]
-
Mar 1st, 2000, 10:50 PM
#5
Lively Member
here is another functon to see if an app is running, covers all of msoffice
Function fIsAppRunning(ByVal strAppName As String, _
Optional fActivate As Boolean) As Boolean
Dim lngH As Long, strClassName As String
Dim lngX As Long, lngTmp As Long
Const WM_USER = 1024
On Local Error GoTo fIsAppRunning_Err
fIsAppRunning = False
Select Case LCase$(strAppName)
Case "excel": strClassName = "XLMain"
Case "word": strClassName = "OpusApp"
Case "access": strClassName = "OMain"
Case "powerpoint95": strClassName = "PP7FrameClass"
Case "powerpoint97": strClassName = "PP97FrameClass"
Case "notepad": strClassName = "NOTEPAD"
Case "paintbrush": strClassName = "pbParent"
Case "wordpad": strClassName = "WordPadClass"
Case Else: strClassName = ""
End Select
If strClassName = "" Then
lngH = apiFindWindow(vbNullString, strAppName)
Else
lngH = apiFindWindow(strClassName, vbNullString)
End If
If lngH <> 0 Then
apiSendMessage lngH, WM_USER + 18, 0, 0
lngX = apiIsIconic(lngH)
If lngX <> 0 Then
lngTmp = apiShowWindow(lngH, SW_SHOWNORMAL)
End If
If fActivate Then
lngTmp = apiSetForegroundWindow(lngH)
End If
fIsAppRunning = True
End If
fIsAppRunning_Exit:
Exit Function
fIsAppRunning_Err:
fIsAppRunning = False
Resume fIsAppRunning_Exit
End Function
-
Mar 1st, 2000, 11:34 PM
#6
Yet Another Way
Code:
hwnd = 999
Do While hwnd > 0
hwnd = FindWindow("OpusApp", vbNullString)
If hwnd > 0 Then
If vbCancel = MsgBox("Please close Microsoft Word and then press " _
& "OK to continue or Cancel to wait.", vbCritical + vbOKCancel, _
"Warning") Then
Exit Sub
End If
End If
Loop
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|