473,320 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Close a Program

Hi
I've opened a program using the code
Dim RetVal
RetVal = Shell("C:\Program Files\Outlook Express\msimn.exe", vbNormalFocus)
Then i create file's and report's and send them off which works fine.
However now i want to close the Application, i've tried
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
objOutlook.Close
but im being told "ActiveX component can't create object", am i missing an DLL have i gone the wrong about it all together?

Any thoughts would be appreciated!

Thanks
Jul 7 '07 #1
4 11451
JConsulting
603 Expert 512MB
Hi
I've opened a program using the code
Dim RetVal
RetVal = Shell("C:\Program Files\Outlook Express\msimn.exe", vbNormalFocus)
Then i create file's and report's and send them off which works fine.
However now i want to close the Application, i've tried
Dim objOutlook As Object
Set objOutlook = CreateObject("Outlook.Application")
objOutlook.Close
but im being told "ActiveX component can't create object", am i missing an DLL have i gone the wrong about it all together?

Any thoughts would be appreciated!

Thanks
the shell command you're using simply launches the application...it doesn't own it. You have two choices. You can use automation to "control" the application as it performs it's actions, or you can use your current method, but then you're going to have to delve into the world of killing PIDs Program ID numbers....much like going into the CTL-ALT-DEL and killing a process.
J
Jul 7 '07 #2
FishVal
2,653 Expert 2GB
the shell command you're using simply launches the application...it doesn't own it. You have two choices. You can use automation to "control" the application as it performs it's actions, or you can use your current method, but then you're going to have to delve into the world of killing PIDs Program ID numbers....much like going into the CTL-ALT-DEL and killing a process.
J
You are right. The code below opens "notepad.exe" and closes it via sending WM_CLOSE to all windows created by the process.

Expand|Select|Wrap|Line Numbers
  1. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
  2.      (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
  3.      lParam As Any) As Long
  4.  
  5. Public Declare Function GetWindowThreadProcessId Lib "user32" _
  6. (ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long
  7.  
  8. Public Declare Function EnumWindows Lib "user32" _
  9.      (ByVal fpCallback As Long, ByVal lParam As Long) As Long
  10.  
  11. Public Const WM_CLOSE = 16
  12.  
  13.  
  14. Public Sub RunAndCloseApp()
  15.  
  16.     Dim lngProcID As Long
  17.  
  18.     lngProcID = Shell("notepad")
  19.     MsgBox "Notepad started, Ok to close it", vbOKOnly, "Close App"
  20.     CloseProcess lngProcID
  21.  
  22. End Sub
  23.  
  24.  
  25. Public Sub clbEnumWindows(ByVal hWnd As Long, ByVal lngParam As Long)
  26.  
  27.     Dim lngProcID As Long
  28.  
  29.     GetWindowThreadProcessId hWnd, lngProcID
  30.     If lngProcID = lngParam Then
  31.         'Debug.Print hWnd, lngProcID
  32.         SendMessage hWnd, WM_CLOSE, 0, 0
  33.     End If
  34.  
  35. End Sub
  36.  
  37.  
  38. Public Sub CloseProcess(ByVal lngProcID)
  39.     EnumWindows AddressOf clbEnumWindows, lngProcID
  40. End Sub
  41.  
  42.  
Jul 7 '07 #3
I keep on getting caught up on things that i forget to thank the people that replied
The above piece of code was just what i was looking for

Thank you !
Jul 12 '07 #4
FishVal
2,653 Expert 2GB
I keep on getting caught up on things that i forget to thank the people that replied
The above piece of code was just what i was looking for

Thank you !
Thanks for response. I'm glad it was helpful for you.
Jul 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tian | last post by:
I have made a program in wxpython, but how could i exit the program? I am using wxFrame for my window, what is the function to close the program? Thanks!!
0
by: Stewart Allen | last post by:
Hi there, I've got some code to open up an Excel workbook but what I want is for the code to pause until the Excel workbook is closed. Sub EditWorkbook(strFile as String) Dim xlApp As...
2
by: Palm Kevin | last post by:
Hello, I have a little problem when I try to use a class of a DLL. Example : I have a DLL with the object MTSync with a function Sync() I try in another program to use this dll like this :...
1
by: Alan Ho | last post by:
Dear All, i used some close program method, e.g. this.hide(), this.dispose() or this.close() , for above 3 method I dont know why i can't open the program in PPC again. and i dont want to use...
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
7
by: Alice | last post by:
Hi, In my program, the user can navigate to many different forms. When they go to the next form, I want the form they have left to close. However, the forms aren't closing. Can anyone tell me...
8
by: koorb | last post by:
I am starting a program from a module with the Sub main procedure and I want it to display two forms for the program's interface, but when I run the program both forms just open and then program...
0
by: Steve Ingram | last post by:
Found out what I'd done, and it wasn't py2exe causug the problem. I wasn't closing the main dialog properly, I was calling Close() instead of Destroy(), so the dialog stayed in memory, basically it...
6
by: coolx | last post by:
Hi. I am using thread function in my project. When I close program.exe(form), it is still working at background and in task manager, i can see program.exe still working. How can I close this...
0
by: winter28 | last post by:
When I try to close a window it will not close. If I have several windows open I get a pop up window that says close program, wait for program to respond, or let windows fix the problem. If I chose...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.