+ Reply to Thread
Results 1 to 8 of 8

How do I execute other application(*.exe) from VBA(Excel) ?

  1. #1
    SUZUKI
    Guest

    How do I execute other application(*.exe) from VBA(Excel) ?

    I am programming by VBA with Excel and I need to execute an executable
    application, which is compiled and saved as "Ap1.exe" by other some compiler.

    How can I start "Ap1.exe" from a VBA program.
    OS: Windows XP,
    Application: Excel 2003
    --
    SUZUKI

  2. #2
    Registered User
    Join Date
    09-07-2004
    Posts
    4
    Shell "C:\windows\ap1.exe", vbNormalFocus

    Unless Ap1.exe is located in a folder that's in the system path, you'll have to specify the full path to the file.

  3. #3
    SUZUKI
    Guest

    Re: How do I execute other application(*.exe) from VBA(Excel) ?

    SUZUKI

    "robertdeniro" wrote:
    > -*Shell "C:\windows\ap1.exe", vbNormalFocus*-


    Thanks a lot.
    Your answer is very helpfull and now I can exute "Ap1.exe" from VBA.

    Another question arose in using function "shell".

    How can I make VBA program wait until Ap1.exe terminates its execution.
    Ap1.exe will operate automatically; it will calculate, output the result
    to a text file, close the result file, and then terminate its execution
    automatically.
    It takes about 1 second for an execution of Ap1.exe.
    I want to let VBA program wait before proceeding to Line4.
    I want to read the result file written by Ap1.exe and process by VBA.
    It is needed to repeat this cycle so many times.

    ---------------------------------------------------------------
    Sub test1
    Line1: FOR I=1 TO 1000
    Line2: cells(1,1)="starting Ap1.exe" ' displaying cell "A1" in Excel
    worksheet
    Line3: Shell "C:\windows\ap1.exe", vbNormalFocus
    Line4: cells(1,1)="terminated execution of Ap1.exe"
    Line5: call read_calculation_result_file
    Line6: call process_calculation_result
    Line7: NEXT I
    End Sub
    ---------------------------------------------------------------


  4. #4
    Bill Martin -- (Remove NOSPAM from address)
    Guest

    Re: How do I execute other application(*.exe) from VBA(Excel) ?

    SUZUKI wrote:
    > SUZUKI
    >
    > "robertdeniro" wrote:
    >
    >>-*Shell "C:\windows\ap1.exe", vbNormalFocus*-

    >
    >
    > Thanks a lot.
    > Your answer is very helpfull and now I can exute "Ap1.exe" from VBA.
    >
    > Another question arose in using function "shell".
    >
    > How can I make VBA program wait until Ap1.exe terminates its execution.
    > Ap1.exe will operate automatically; it will calculate, output the result
    > to a text file, close the result file, and then terminate its execution
    > automatically.
    > It takes about 1 second for an execution of Ap1.exe.
    > I want to let VBA program wait before proceeding to Line4.
    > I want to read the result file written by Ap1.exe and process by VBA.
    > It is needed to repeat this cycle so many times.
    >
    > ---------------------------------------------------------------
    > Sub test1
    > Line1: FOR I=1 TO 1000
    > Line2: cells(1,1)="starting Ap1.exe" ' displaying cell "A1" in Excel
    > worksheet
    > Line3: Shell "C:\windows\ap1.exe", vbNormalFocus
    > Line4: cells(1,1)="terminated execution of Ap1.exe"
    > Line5: call read_calculation_result_file
    > Line6: call process_calculation_result
    > Line7: NEXT I
    > End Sub
    > ---------------------------------------------------------------
    >

    ----------------------

    Can you just try to open the output file, and if an error is detected loop back
    and try again ... and again? Maybe wait 1 second first before starting the looping?

    Bill

  5. #5
    SUZUKI
    Guest

    Re: How do I execute other application(*.exe) from VBA(Excel) ?

    SUZUKI

    "Bill Martin -- (Remove NOSPAM from addre" wrote:
    > Can you just try to open the output file, and if an error is detected loop back
    > and try again ... and again? Maybe wait 1 second first before starting the looping?
    > Bill


    Thanks a lot.
    I am very glad to know very simple and easy method presented by you.
    This method, however, may consume CPU resource, and errors of too many
    times may cause some trouble.
    Is there more elegant and safe way to let VBA program idle until
    Ap1.exe terminates.


  6. #6
    Registered User
    Join Date
    08-11-2005
    Location
    Netherlands Waddinxveen
    Posts
    81
    Quote Originally Posted by SUZUKI
    SUZUKI
    Thanks a lot.
    I am very glad to know very simple and easy method presented by you.
    This method, however, may consume CPU resource, and errors of too many
    times may cause some trouble.
    Is there more elegant and safe way to let VBA program idle until
    Ap1.exe terminates.
    This would require using API functions to make a snapshot and API process functions
    you can find information on: URL: API page

  7. #7
    SUZUKI
    Guest

    Re: How do I execute other application(*.exe) from VBA(Excel) ?

    Thanks a lot for infomation on API.
    Now, I underatand that I should learn API.
    --
    SUZUKI


  8. #8
    Bird
    Guest

    Re: How do I execute other application(*.exe) from VBA(Excel) ?

    Hello,
    I also tried this, and initially it appeared to work. my executable is a
    compiled fortran program. The executable works ok when I run it outside of
    Excel, but when I use the shell command, it doesnt.

    Sub run_for()
    Dim retApp As Double
    retApp = Shell("L:\methods\for.exe", vbMinimizedFocus)

    End Sub

    The .exe accesses an input file from within L:\methods. When I execute from
    the subroutine, does it need a full pathname in the exe as opposed to just
    the filename?

    Bird


    "robertdeniro" wrote:

    >
    > -*Shell "C:\windows\ap1.exe", vbNormalFocus*-
    >
    > Unless Ap1.exe is located in a folder that's in the system path, you'll
    > have to specify the full path to the file.
    >
    >
    > --
    > robertdeniro
    > ------------------------------------------------------------------------
    > robertdeniro's Profile: http://www.excelforum.com/member.php...o&userid=14173
    > View this thread: http://www.excelforum.com/showthread...hreadid=396096
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1