Results 1 to 7 of 7
  1. #1
    Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Run C or C++ Program (Office 2002 - VB/VBA)

    Is it possible to run or call a C Program from VB or VBA code? If so can someone point me in the direction of how?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run C or C++ Program (Office 2002 - VB/VBA)

    If you mean a compiled C/C++ program (*.exe), you can call it like any other executable, using Shell or ShellExecute. Shell is simple:

    Shell "full path and file name of executable"

    For ShellExecute, see for instance <post#=173519>post 173519</post#>, but a search will yield many others.

    If you want to execute C/C++ source code in VB/VBA, it can't be done; you would have to convert the code to VBA.

  3. #3
    Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run C or C++ Program (Office 2002 - VB/VBA)

    Ok this is going to sound like a really simple and stupid question (comes from a lack of C knowledge)...if the C Program has been compiled then do I have to do something else in order for it to be a *.exe program?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run C or C++ Program (Office 2002 - VB/VBA)

    I'm not a C programmer myself, but I assume that compiling a C program results in a file with extension .exe. You shouldn't have to do anything else.
    (You can also create other types of file with C/C++, such as DLL's and ActiveX controls, but you wouldn't call that a program)

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Run C or C++ Program (Office 2002 - VB/VBA)

    Hi,
    Under the Build menu, there should be an option to build the relevant .exe file (probably underneath Compile). Once that is done you can then call it as Hans mentioned.
    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Lounger
    Join Date
    Jan 2001
    Location
    Virginia, USA
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run C or C++ Program (Office 2002 - VB/VBA)

    Thanks everyone I think I figured it out!

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Run C or C++ Program (Office 2002 - VB/VBA)

    Compiling produes either a .EXE or a .DLL, depending on the type of the project.

Posting Permissions

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