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
4 11451
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
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. -
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
-
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
-
lParam As Any) As Long
-
-
Public Declare Function GetWindowThreadProcessId Lib "user32" _
-
(ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long
-
-
Public Declare Function EnumWindows Lib "user32" _
-
(ByVal fpCallback As Long, ByVal lParam As Long) As Long
-
-
Public Const WM_CLOSE = 16
-
-
-
Public Sub RunAndCloseApp()
-
-
Dim lngProcID As Long
-
-
lngProcID = Shell("notepad")
-
MsgBox "Notepad started, Ok to close it", vbOKOnly, "Close App"
-
CloseProcess lngProcID
-
-
End Sub
-
-
-
Public Sub clbEnumWindows(ByVal hWnd As Long, ByVal lngParam As Long)
-
-
Dim lngProcID As Long
-
-
GetWindowThreadProcessId hWnd, lngProcID
-
If lngProcID = lngParam Then
-
'Debug.Print hWnd, lngProcID
-
SendMessage hWnd, WM_CLOSE, 0, 0
-
End If
-
-
End Sub
-
-
-
Public Sub CloseProcess(ByVal lngProcID)
-
EnumWindows AddressOf clbEnumWindows, lngProcID
-
End Sub
-
-
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 !
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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!!
|
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...
|
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 :...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |