Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to open other applications....vb6

Posted on 2004-08-20
6
Medium Priority
?
653 Views
Last Modified: 2008-03-17
I have command buttons to:

Shell "Excel.exe"                                    '<-- to open just blank excel
Shell "C\MyFolder\MyFile.xls"                  '<-- to open MyFile.xls

I need the same two lines to open Access and Word.

Thanks,
0
Comment
Question by:Mike Eghtebas
[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
6 Comments
 
LVL 15

Expert Comment

by:Colosseo
ID: 11856203
Hi

hope this is what you mean

Shell "msaccess.exe" '<--- opens access

Shell "winword.exe" '<---- opens word

Regards

Scott
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 11856813
Shell "winword.exe" '<---- error 53: File not found

Same with other two.
0
 
LVL 15

Expert Comment

by:Colosseo
ID: 11856830
Hi

Have you searched your computer for winword.exe and msaccess.exe?

If installed to the default folder they should both be in something like

c:\Program Files\Microsoft Office\Office10\

You might need to put in the full path, for example on my computer it would be

shell "c:\Program Files\Microsoft Office\Office10\msaccess.exe"

 but i wouldnt have thought so

Scott
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:Mandtis
ID: 11857024
Here's some old VB6 code I used myself on a program to execute external programs, sorry if the comments and variable names are in spanish.
You would call it like:
Ejecutar "c:\Program Files\Microsoft Office\Office10\msaccess.exe" , True/False , ""
Where the first parameter is the program to launch, the second one is if we want the program to run visible/minimized/hidden, and the last one are the parameters we want to give it.
Functions DirectorioDelPrograma will return the dir were the exe file is stored and UnidadDelPrograma the drive (in the previous case it would return "Program Files\Microsoft Office\Office10" and "C:") so we can switch to that drive&dir before launching it, and return to the folder where we were previously.
If the "program" we are launching ends with *.reg, it will silently be imported with regedit, if it is a file associated with a program, it will be opened with that program (if we do a Ejecutar c:\temp.txt, temp.txt will open with Notepad).
Hope it helps.

----------[cut]----------
'Mirar si existe un exe, si es asi cambiar a su directorio,
'ejecutarlo, y volver al viejo dir
Public Function Ejecutar(ByVal tmpPrograma As String, tmpVisible As Boolean, ByVal Parametros As String) As Double
Dim locUnidad, locDir, locExtension As String
  On Error GoTo HayError
 
  locExtension = Mid(tmpPrograma, Len(tmpPrograma) - 3, 4)
  If ExisteFichero(tmpPrograma) Then
    If locExtension = ".exe" Or locExtension = ".bat" Or locExtension = ".com" Then
      locDir = CurDir()
      locUnidad = UnidadDelPrograma(locDir)
      ChDrive UnidadDelPrograma(tmpPrograma)
      ChDir DirectorioDelPrograma(tmpPrograma)
      If tmpVisible Then
        Ejecutar = Shell(tmpPrograma & " " & Parametros, vbNormalFocus)
      Else
        Ejecutar = Shell(tmpPrograma & " " & Parametros, vbHide)
      End If
      ChDrive locUnidad
      ChDir locDir
    ElseIf locExtension = ".reg" Then
      Ejecutar = Shell("regedit -s " & tmpPrograma, vbNormalFocus)
    Else
      Ejecutar = Shell("start " & tmpPrograma, vbNormalFocus)
    End If
  End If
  GoTo Continuar
HayError:

Continuar:
End Function


'Recibe un programa con path, devuelve ese path
Public Function DirectorioDelPrograma(ByVal tmpPrograma As String) As String
Dim locPosicion As Integer
  On Error GoTo HayError
  locPosicion = InStrRev(tmpPrograma, "\")
  DirectorioDelPrograma = Mid(tmpPrograma, 1, locPosicion)
  GoTo Continuar
HayError:

Continuar:
End Function

'Devuelve la unidad de un programa con path entero
Public Function UnidadDelPrograma(ByVal tmpPrograma As String) As String
  On Error GoTo HayError
  UnidadDelPrograma = Mid(tmpPrograma, 1, 1)
  GoTo Continuar
HayError:

Continuar:
End Function
----------[cut]----------
0
 
LVL 5

Accepted Solution

by:
Z03niE earned 1000 total points
ID: 11857601
Wow.... what a huge code you got there Mandtis .
I don't think shell command can execute other program than executables(say .exe, .bat or .com).
I think to do this you should use API's shell execute function .

'First off declare the function
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

'then use it in the command button, say the name of the command button is CMDLauncher in a form named form1
Private Sub CMDLauncher_Click()
        Dim I As Long
        'this one runs the excel document
        I = ShellExecute(Form1.HWnd, "open", "C\MyFolder\MyExcellFile.xls", vbNullString, vbNullString, 1)  
        'this one runs the word document
        I = ShellExecute(Form1.HWnd, "open", "C\MyFolder\MyWordFile.doc", vbNullString, vbNullString, 1)  
        'this one runs the access document
        I = ShellExecute(Form1.HWnd, "open", "C\MyFolder\MyAccessFile.mdb", vbNullString, vbNullString, 1)  

        'this one runs the excel application
        I = ShellExecute(Form1.HWnd, "open", "excel", vbNullString, vbNullString, 1)  
        'this one runs the word application
        I = ShellExecute(Form1.HWnd, "open", "winword", vbNullString, vbNullString, 1)  
        'this one runs the access application
        I = ShellExecute(Form1.HWnd, "open", "msaccess", vbNullString, vbNullString, 1)  

        'and so on , remember to change the form1 with your form name.
end sub

Hope that work for you.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 11862109
Thanks.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 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