Mike Eghtebas
asked on
How to open other applications....vb6
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,
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,
ASKER
Shell "winword.exe" '<---- error 53: File not found
Same with other two.
Same with other two.
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.e xe"
but i wouldnt have thought so
Scott
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.e
but i wouldnt have thought so
Scott
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.e xe" , 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(tmpProgr ama)
ChDir DirectorioDelPrograma(tmpP rograma)
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(ByVa l 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]----------
You would call it like:
Ejecutar "c:\Program Files\Microsoft Office\Office10\msaccess.e
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)
If locExtension = ".exe" Or locExtension = ".bat" Or locExtension = ".com" Then
locDir = CurDir()
locUnidad = UnidadDelPrograma(locDir)
ChDrive UnidadDelPrograma(tmpProgr
ChDir DirectorioDelPrograma(tmpP
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(ByVa
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]----------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
hope this is what you mean
Shell "msaccess.exe" '<--- opens access
Shell "winword.exe" '<---- opens word
Regards
Scott