473,378 Members | 1,421 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,378 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 11468
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.