Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
I have a workbook that uses the shell() command to open an external
executable program and performs a database search using the external program. The external program then dumps the data from the search into an excel spreadsheet. This task is executed about 30 times. Each time a new search is performed, a new program window is opened. So after the 30 searches are complete and the data is transferred, I have to close the 30 windows. Does anyone know how to close the external program window with VBA code...somthing like application quite?? Any example code would be helpful. Regards, ZABU |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
Does this help?
http://google.com/groups?selm=e5U8T%...GP12.phx. gbl -- Vasant "ZABU" wrote in message ... I have a workbook that uses the shell() command to open an external executable program and performs a database search using the external program. The external program then dumps the data from the search into an excel spreadsheet. This task is executed about 30 times. Each time a new search is performed, a new program window is opened. So after the 30 searches are complete and the data is transferred, I have to close the 30 windows. Does anyone know how to close the external program window with VBA code...somthing like application quite?? Any example code would be helpful. Regards, ZABU |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
Hi ZABU,
Usually we should wait for a process to exit normally, that is the way Vasant has shown. If we want to terminate a process forcely, we can use the TerminateProcess API, but this will make the process do not exit properly. So if Vasant's suggestion did not work for your senario, can you tell us what kind of external program you want to terminate? Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
The process appears t o be completed, but teh window is still open. All
taht is done to close the window is to manually click the "X" in the upper right hand corner of the main window.....about 30 times. I reviewed teh informatino that Vasant forwarded, but I am not very familure with using the API. I have been looking around and have found numerous references to the "Sendandwait" macro, but have not seen an example that would sufficiently demonstrate the use of API. However, I must admit I have not yet found time to test any of the suggested options to this date. I feel that it should work, but no time to test. Do you have any further examples that would demonstrate and comment on how the "Sendandwait" works or furthur more how the TerminateProcess API works? Any further information is very welcome and greatly appreciated! Regards, ZABU ""Peter Huang"" wrote in message ... Hi ZABU, Usually we should wait for a process to exit normally, that is the way Vasant has shown. If we want to terminate a process forcely, we can use the TerminateProcess API, but this will make the process do not exit properly. So if Vasant's suggestion did not work for your senario, can you tell us what kind of external program you want to terminate? Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
Hi ZABU,
In the Sub Test, we will post a message to the window of notepad and tell it to close, we need to find the applicaiton's main window first before use the method. In the Sub Test2, we will use the terminateprocess, but as I said before it is not recommend to do so, which may cause some underlying job. The TerminateProcess function is used to unconditionally cause a process to exit. Use it only in extreme circumstances. The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess. TerminateProcess initiates termination and returns immediately. This stops execution of all threads within the process and requests cancellation of all pending I/O. The terminated process cannot exit until all pending I/O has been completed or canceled. For detailed information, you may take a look at the link below. http://msdn.microsoft.com/library/de...us/dllproc/bas e/terminateprocess.asp Here goes the code. Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Public Const WM_CLOSE = &H10 Public Const INFINITE = -1& Public Const SYNCHRONIZE = &H100000 Public Const STANDARD_RIGHTS_REQUIRED = &HF0000 Sub Test() Dim hwnd As Long hwnd = FindWindow("NotePad", vbNullString) Dim rt As Long rt = PostMessage(hwnd, WM_CLOSE, 0&, 0&) End Sub Sub Test2() Dim task As Long Dim handle As Long Dim result As Long task = Shell("notepad.exe", vbNormalFocus) handle = OpenProcess(SYNCHRONIZE Or STANDARD_RIGHTS_REQUIRED Or &HFFF, False, task) result = TerminateProcess(handle, 0) result = CloseHandle(handle) End Sub Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
Hi ZABU,
Have you tried my suggestion? Did that work for you? If you still have any concern on this issue, please feel free to post here. Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
Peter,
I have yet to try the code, but appreciate your time and effort with the additional information. Work is currently shifting gears to supply information abroad and I am having to compile that information...very time consuming. Please monitor and hopefully I will be able to test next week and notify you of any questions. I am sure that I will have a few. Change of topic....do you know of some code that can be used to search a server for any document that would contain a sting of text within a hyperlink of work documents (EX..Servername1\file location....looking for "Servername1" text)? My corp is renaming a server and I have to come up with the number of links that would have to be updated...additionally, have any code that could change the Servername from "Servername1" to "Servername2" ?? Working on a Windows 2000 Platform. Please enlist any help from your colleagues familiar with Word or Outlook as these will be issues also. I would need to change any embedded reference to the old server to the new server. Thanks for any assistance in advance! Best Regards, ZABU ""Peter Huang"" wrote in message ... Hi ZABU, Have you tried my suggestion? Did that work for you? If you still have any concern on this issue, please feel free to post here. Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
Hi ZABU,
Now I am researching the issue, I will get back here and update you with new information ASAP. Have a nice day! Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#9
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
Hi ZABU,
Based on my searching, I think we can utilize the index service of windows to search the file which contain the specified keyword. Then we can use automation to open the word document and then make the http link replace. Here is KB with VB.NET, but we can do the similar thing in VB6 or vba using ADO. HOW TO: Use an ASP.NET Application to Query an Indexing Service Catalog by Using Visual Basic .NET (820105) http://support.microsoft.com/default...B;EN-US;820105 Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
#10
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close External Application using VBA
Hi ZABU,
Have you tried my suggestion? If you still have any concern on this issue, please feel free to let me know. Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Trying to close Excel Application in IE | Excel Discussion (Misc queries) | |||
macro to close excel application other than application.quit | Excel Programming | |||
Application.Close | Excel Programming | |||
Close or Exit application | Excel Programming |