Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to invoke an application in VB?

Posted on 2003-02-18
11
Medium Priority
?
779 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

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.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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

564 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