Ozgrid Excel Help & Best Practices Forums

Excel Training / Excel Dashboards Reports

Results 1 to 2 of 2

Thread: VBA: Close program

  1. #1
    Join Date
    10th September 2003
    I am having difficulty closing a external program from within xcel.
    I have a macro that opens one of two programs that import data from the com port. There are times when I need to close one program and open the other.
    The code I use to open the program is:

    Sub OpenDetails()
    ' OpenDetails Macro

    ' Keyboard Shortcut: Ctrl+s
    On Error Resume Next
    RetVal = Shell("C:\Program Files\METTLER TOLEDO\BalanceLink\BAL32.exe")
    Application.Wait (Now + TimeValue("00:00:02")) 'Give time to load
    AppActivate Application.Caption

    Sheets("Detail").Visible = True
    Sheets("Instructions").Visible = False

    End Sub
    Can anyone help please?

    Excel Video Tutorials / Excel Dashboards Reports

  2. #2
    Join Date
    7th March 2003
    Essex, England
    Hi Johnc and welcome,

    Try this example, which opens and then closes NotePad.
    Sub CloseNotePad() 
        If Range("TaskID").Value > 0 Then 
            ' Close know copy of note pad 
            AppActivate Range("TaskID").Value 
            Application.SendKeys "%{F4}", True 
        End If 
    End Sub 
    Sub LoadNotePad() 
        ' Open Notepad And return program's task ID 
        Range("TaskID").Value = Shell("C:\notepad.EXE", 1) 
    End Sub 
    You will need to change the path in the Shell command.

    The Range("TaskID") is a single cell named range.

    Hopefully you can adapt this to suit your application.


    Excel Video Tutorials / Excel Dashboards Reports

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Replies: 4
    Last Post: October 8th, 2005, 09:49
  2. saving file causes program to close
    By ajisgod in forum Excel General
    Replies: 31
    Last Post: September 23rd, 2005, 05:00
  3. close program VBA
    By rpfeil in forum Excel General
    Replies: 2
    Last Post: September 14th, 2005, 04:45
  4. Close my Program but leave other workbooks open?
    By jshayler in forum Excel General
    Replies: 4
    Last Post: April 7th, 2005, 21:52
  5. VBA to close Excel Window on close last workbook
    By Dovrox in forum Excel General
    Replies: 2
    Last Post: September 22nd, 2004, 18:06


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts