?
Solved

How to invoke an application in VB?

Posted on 2003-02-18
11
Medium Priority
?
774 Views
Last Modified: 2010-05-18
As titled, if I want to invoke an application, such as Outlook in a vb program, how to write the code?
0
Comment
Question by:chpchai
[X]
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
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 4

Expert Comment

by:Frog357
ID: 7979700
Shell "c:\somedir\name_of_exe.exe", vbNormal

The last parameter specifies how the program will be loaded (normal, minimized, maximized, etc.)
0
 

Author Comment

by:chpchai
ID: 7979849
But the path maybe different in different computers, is there any other method not to hardcode the path? or can I get the path with vb code?
0
 
LVL 5

Expert Comment

by:dgorin
ID: 7980025
For many office apps and other OLE apps, you can start them by creating an instance of the application as an object in your code.


    Dim oXL as Excel.Application
    Set oXL = CreateObject("Excel.Application")


0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Expert Comment

by:Lio
ID: 7980489
Here's a good one too

In some Programms like in Adobe Arcrobat Reader, you can open the app and load a file...

ex:
Shell "C:\Programme\Adobe\Acrobat 4.0\Acrobat\Acrobat.exe C:\Test.pdf", vbNormal

(just make a space between the exe-file Path and the full filename)
0
 
LVL 1

Expert Comment

by:Sanker
ID: 7980849
You could use a common dialog box (cdb) to ask the user what file to open, if this is applicable.

Private Sub Command1_click()
dim rc as Double
    cdb.DialogTitle = "Select the exe you wish to open..."
    cdb.DefaultExt = "*.exe"
    cdb.filename = "*.exe"
    cdb.Filter = "*.exe" | "*.*"
    cdb.ShowOpen
rc = shell(cdb.filename), VbNormal
End Sub
0
 

Author Comment

by:chpchai
ID: 7985074
To dgorin, I have tried your code,

   Dim oXL as Excel.Application
   Set oXL = CreateObject("Excel.Application")

but the excel application not invoked actually. Maybe an object is created, but how to show it?
0
 
LVL 4

Expert Comment

by:Frog357
ID: 7989387
If you need to open a file associated with a specific application as in .eml files (for Outlook Express) you should use the API for ShellExecuteA  This will allow you to open any file the same as double-clicking or if you went to start->run and typed in it.
0
 
LVL 5

Expert Comment

by:dgorin
ID: 7990462
You also need to add Excel in your project references.
0
 

Author Comment

by:chpchai
ID: 7991100
To dgorin, I have add the Excel library already, otherwise can't be compiled. It is supposed the excel application will be shown after create the object?
0
 
LVL 5

Accepted Solution

by:
dgorin earned 60 total points
ID: 8010203
You need to set the excel visible property to true to display excel.

dim oXL as Excel.Application
set oXL = CreateObject("Excel.Application")
oXL.visible = true
oXL.Workbooks.Add

 
0
 

Author Comment

by:chpchai
ID: 8016265
I have found that outlook don't have visible property, how to make it visible then?
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

764 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