Shell command in VB 6

D

Thread Starter

D

Consider the command:
Dim t
t=shell("Excel",1)

The problem is that i cannot get Excel or any of the microsoft office application to start. However Notepad starts.

Any suggestion as to what i'm missing?

Thanks
D
 
You Need to Know About Path.
Like That "C:\\Program Files\\Microsoft Office\\"
Notepad is already in Path.
 
Syntax

Shell(pathname[,windowstyle])

You don't need the T=
Just SHELL "C:\yada\yada\excel.exe"
You need to use the full path or enviornment var.
The reason you had to use the T= is because you put it in parenthesis, VB thinks that you are calling a function and expects a return value..
I think that it will return a succees value that way if you need it..
 
You probably need the full path

ie

Dim t
t=shell("c:\program files\microsoft office\office10\Excel",1)

or you may have to use the 8.3 approach

Dim t
t=shell("c:\progra~1\micros~1\office10\Excel",1)

These are my paths, yours may be a bit different.
Notepad probably works because the windows directory is one of your environment vars...

good luck
rich
 
C

Copied from the net

This will open the program:
Shell "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE"

If you want to have the program load with the file in it, use this:
Shell "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE" "C:\My Documents\Query.mdb"

Or you could say something like this:
location = Chr(34) + "C:\Program Files\Microsoft Office\Office10\EXCEL.EXE" + Chr(34)
file = Chr(34) + Text1.Text + Chr(34)
Shell location + " " + file, vbNormalFocus
 
Try something like this:

Dim dTaskID As Double

dTaskID = Shell(path,vbNormalFocus)

where path is D:\Program Files\Microsoft Office\excel.exe

Hope that helps,

R. Dutra
 
Thank You for the Info.

I've used the Shell Command to Launch non-MS program/file: Oracle Forms / Executable Fmx file.

Private Sub Form_Load()
Dim dTaskID As Double, path As String, file As String

path = "C:\Oracle\forms\bin\ifrun60.exe"
file = "C:\Oracle\Assignments\As_submit_CutDown01.fmx"
dTaskID = Shell(path + " " + file, vbNormalFocus)

'MsgBox ("Program loaded")
End
End Sub

Cheers,
Pw.x
 
I don't like to go over what everyone has already said but basically, whichever editor you are working in; be it Access VBA, Excel VBA or standalone VB, until compiled in a dir or told otherwise they all assume their own paths to be the path to work with. You need to tell the editor you are looking for the file/program somewhere else, hence normally we would use an absolute path. Absolute paths are much more preffered method in this case, as you are referencing a program, a file on the other hand can change name or location, this would hit another approach of a possible search or just a dynamic path. I hope this along with the other pieces of code here (some of which are very nice) help you understand what you are doing
better.

Thanks,
Ashley
 
<p>Try this code it will work.
<pre>
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

Const SW_HIDE = 0
Const SW_SHOWNORMAL = 1
Const SW_NORMAL = 1
Const SW_SHOWMINIMIZED = 2
Const SW_SHOWMAXIMIZED = 3
Const SW_MAXIMIZE = 3
Const SW_SHOWNOACTIVATE = 4
Const SW_SHOW = 5
Const SW_MINIMIZE = 6
Const SW_SHOWMINNOACTIVE = 7
Const SW_SHOWNA = 8
Const SW_RESTORE = 9
Const SW_SHOWDEFAULT = 10
Const SW_MAX = 10

Private Sub cmdExcel_Click()
ShellExecute 0&, vbNullString, "excel", vbNullString, _
vbNullString, SW_SHOWDEFAULT
End Sub

'in third vbnullstring arguement pass the file path
</pre>
 
This is really a great information for me. I found your code here, what I actually require, using the text1.text.
 
this code is not working:

Private Sub Command1_Click()
Dim str, str1 As String
str = Chr(34) + "c:\Program Files\Microsoft Office\office\Winword.exe" + Chr(34)
str1 = Chr(34) + "D:\tyty.doc" + Chr(34)
Dim id As Double
MsgBox str
MsgBox str1
Shell str + " " + str1, vbNormalFocus

End Sub
 
This works, but program(s) always load miminimized, or in some cases show up on taskbar, but won't "restore / maximize" if clicked on...

Thanks
 
Replace Excel in Shell command with full path of Excel executable file. like
C:\Program Files\Microsoft Office\Office\Excel.exe

i think it will work.
 
I write a code in vb6.0

dim tmp
tmp = Shell("c:\Test.txt", vbMaximizedFocus)

But it gives an error "Invalid Procedure Or call argument"

Can anybody please help me and send a mail at [email protected]

Thanks in Advance
 
Top