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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Way to Get Excel.exe Process ID 1

Status
Not open for further replies.

RoguePoet01

Programmer
Oct 1, 2003
302
0
0
US
Hi,

I found a neat little snippit that will let me close any program given the process id, but I need to be able to find out the process id since it's dynamically generated.

Any ideas?

Thanks.
 
Try this...

[green]'Module[/green][blue]
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const WM_CLOSE = &H10[/blue]

[green]'Form[/green][blue]
Private Sub Command1_Click()
Dim xlmain As Long
xlmain = FindWindow("xlmain", vbNullString)
Call SendMessageByString(xlmain, WM_CLOSE, 0&, 0&)
End Sub[/blue]

If you know the filename open in excel you can use..
[blue]
Private Sub Command1_Click()
Dim xlmain As Long
xlmain = FindWindow("xlmain", "microsoft excel - book1")
Call SendMessageByString(xlmain, WM_CLOSE, 0&, 0&)
End Sub[/blue]

Good Luck!
 
Thanks, I'll try it.

The problem is that some part of Excel is getting hung up. When I quit it in my program, it is set to nothing, but it stays stuck there in memory.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top