close a none MS Office running program

nmk34

New Member
Joined
Apr 12, 2022
Messages
40
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I need an excel VBA to close a program that runs when an excel workbook starts but i have no luck in closing it when a userform1 terminate! does anybody have a general subroutine i can use?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
No idea on how your project is so this could only be a suggestion. In my example I'm opening Notepad.exe from Excel.
I'm assuming that you would have something like this in your Workbook_Open macro to launch the program Notepad:
VBA Code:
Private Sub Workbook_Open()
    Dim x As Variant
    x = Shell("C:\Windows\Notepad.exe", vbNormalFocus)
End Sub
Now you need to add this other line of code at the end of the macro where you close your UserForm1:
Code:
Call CloseProgram
and add this macro to a vbe module. It searches in Windows the process and terminates it:
Code:
Private Sub CloseProgram()
    Dim Process As Object
    For Each Process In GetObject("winmgmts:").ExecQuery("Select Name from Win32_Process Where Name = '" & "Notepad.exe" & "'")
        Process.Terminate
    Next
End Sub
See if you adapt this suggestion to your project.
 
Upvote 0
Solution
Oh, not bad for a guess :giggle:, glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,214,992
Messages
6,122,631
Members
449,095
Latest member
bsb1122

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top