Solved

Loading programs from another program

Posted on 1998-08-24
11
142 Views
Last Modified: 2010-04-30
I need the code for a command button on a program...to load another program I have made.
0
Comment
Question by:Klueny2
[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
  • 5
  • 3
  • 3
11 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1430837
You have to use the shell function

Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", vbMaximizedFocus)      

vbHide      0      Window is hidden and focus is passed to the hidden window.
vbNormalFocus      1      Window has focus and is restored to its original size and position.
vbMinimizedFocus      2      Window is displayed as an icon with focus.
vbMaximizedFocus      3      Window is maximized with focus.
vbNormalNoFocus      4      Window is restored to its most recent size and position. The currently active window remains active.
vbMinimizedNoFocus      6      Window is displayed as an icon. The currently active window remains active.
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430838
Hi,

    Option Explicit
    Dim ret3&
    Private Declare Function ShellExecute Lib "shell32.dll" Alias _
   "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
   String, ByVal lpFile As String, ByVal lpParameters As String, _
   ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
   
   
    Private Sub cmdRunCalculator_Click()

    ' Run any program EXE,COM from here.

      ret3& = ShellExecute(Me.hwnd, "Open", "calc.exe", "", App.Path, 1)

     End Sub


      Private Sub Form_Load()
      End Sub


0
 

Author Comment

by:Klueny2
ID: 1430839
Also, lets say I wanted to send this program to somebody else in a zip file...and after they unzip it,...will the command button still work to open the prog? if not, how can I do this if I can?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:waty
ID: 1430840
I don't anderstand your question
0
 

Author Comment

by:Klueny2
ID: 1430841
Ok, sorry..I need to know the code so that a command button opens up another form in the same program.
0
 
LVL 14

Expert Comment

by:waty
ID: 1430842
Sub cmdButton_Click()

   frm2.Show

End Sub
0
 

Author Comment

by:Klueny2
ID: 1430843
It gives me a run-time error, and says object required
0
 

Author Comment

by:Klueny2
ID: 1430844
It gives me a run-time error, and says object required
0
 
LVL 3

Accepted Solution

by:
a111a111a111 earned 50 total points
ID: 1430845
the answer to your Question: "I need the code for a command button on a program...to load another program I have made."

Let say your program name is MyProgram.exe

THIS IS A WORKING CODE.
use this code as is first , then change the line,
ret3& = ShellExecute(Me.hwnd, "Open", "calc.exe", "", App.Path, 1)

with this line,
ret3& = ShellExecute(Me.hwnd, "Open", "MyProgram.EXE", "", App.Path, 1)

where MyProgram.EXE is your program that you wish to run..
(Note: Path is the path you choose: c:\MyProgram.EXE , E:\prog\MyProgram.EXE and so on.

If you have any question email to shay@hili.com or post here.


========== start code =========
'in your general declaration:
Option Explicit
           Dim ret3&
           Private Declare Function ShellExecute Lib "shell32.dll" Alias _
          "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
          String, ByVal lpFile As String, ByVal lpParameters As String, _
          ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
     
           
     Private Sub Command1_Click()

           ' Run any program EXE,COM from here.
            ' Replace the calc.exe with your program "MyProgram.EXE"
             ret3& = ShellExecute(Me.hwnd, "Open", "calc.exe", "", App.Path, 1)

     End Sub

=========== end code ========
Shay.

0
 

Author Comment

by:Klueny2
ID: 1430846
I'm sorry...where do I put this following code? I'm kinda new and have no idea where it goes..

Option Explicit
    Dim ret3&
    Private Declare Function ShellExecute Lib "shell32.dll" Alias _
   "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As _
   String, ByVal lpFile As String, ByVal lpParameters As String, _
   ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1430847
The code
Option Explicit
 Dim ret3&
 Private Declare Function........
Go in (general) (Declarations)

If need more help or to fix your code email to shayplace@hotmail.com
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

734 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