Calling a program?

Posted on 2000-04-17
Last Modified: 2010-05-02
How do i call another application from my VB6.0 program? example: i want to open an application like MS Word.

How do i make that same app a part of my VB program?

so, if i have a form with two buttons i want the first to open an app (word in this case) located at c:\program files\office\winword.exe. button 2 should be able to open the same app from within the program(not calling a UNC).

Can you help me?
Question by:hirschhouse
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1

Expert Comment

ID: 2724732
I am going to get beat up now here.:). One you can use Shell() place a path of the word. Another is to use ShellExecute API function.

Expert Comment

ID: 2724737
Here is a link that might help you. It uses 2 API's There one of which is a new one for win2k. apiFindWindow.

Expert Comment

by:Glen Richmond
ID: 2724899
why use shell? Use the office reference to allow you to expose all the functionality of word thorough the object model ie.
dim wrd As Word.Application
wrd.Application.Visible = True
("FileNameAsString"), , True
using the object variable method you can do anything in code you could do if using word itself.

check out the properties and method avalible.

if you need more help mail me
good luck
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now


Expert Comment

by:Glen Richmond
ID: 2724908
also you can expose the functionality of any ole application using its object model. check your references and ocx controls to see whats avalible.

Accepted Solution

tdtomlins earned 110 total points
ID: 2724983
This should be more than worth the points :-)).

When you say Same app within the program do you mean onto your VB Form?

And is it Word your trying to use?  If yes to both then the solution is yours

you can use the Shell to start a program
example of shell:

Dim strlong As Long
strlong = Shell("c:\test\testexe.exe", vbNormalFocus)

Second example of opening a File (word specifically
' you can use the below code referencing what ever program your using but this way allows you to insert text as well

'Make references to Microsoft Word 8 Object Libarary

Open Word outside:
Dim mobjWord As Word.Application
'Under a command Button
Dim strText As String
  strText = "This text was passed to the " _
    & "Microsoft Word ActiveX Server."
    Dim objDoc As Object
    Set mobjWord = New Word.Application
    Set objDoc = mobjWord.ActiveDocument
    objDoc.Range.InsertBefore strText
    mobjWord.Visible = True

'Closing out Word
On Error Resume Next
   mobjWord.Quit False
   Set mobjWord = Nothing

2nd opening onto your program:

USE the OLE container Control on your tools to import word into your document if you have troubles with this try help MSDN.MICROSOFT.COM goto search.

I can also get you a sample program of an OLE as well if you have troubles.

This should do you well.
Tom T.

Author Comment

ID: 2727798
Adjusted points from 100 to 110

Author Comment

ID: 2727799
Outstanding, that's what i was looking for!

Expert Comment

ID: 2728024
thats actually what the other person and i talked about. I gave one solution the other gave another this one just put it together. Where is the fare game ? I think points were supposed to go to the other person who commented

Author Comment

ID: 2728237
He gave me the code i needed to drop right in to my project. yes you both did a great job, but the code didn't work 'till i saw tdtomlins ex.

Thank you all for your info, it helps me alot and i look forward to more help.

Thank you all once again.



Expert Comment

by:Glen Richmond
ID: 2728841
yeh cheers for that i think Marine said it all.

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month7 days, 11 hours left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question