I can't find out why, whenever I try to run Shell instruction, I get run time error 5 saying "Invalid procedure call or argument"
Printable View
I can't find out why, whenever I try to run Shell instruction, I get run time error 5 saying "Invalid procedure call or argument"
Lets see your c0d.
VB Code:
Sub cmdButton_Click() Shell ("C:\directory\file.xls") End Sub
Remove the parenthesis and it should be ok but if you right click on Shell does it bring up the object browser to it?
In fact, I've tried either with or without parenthesis, and it gives the same error. When I run the user form with the button, nothing appears with right click.
No, i mean to right click on the work Shell to see if its linked in the Object Browser. Not at runtime. ;)
In the object browser I can find it in the Interaction class.
Ok, thats good so far. Its in the "VBA.Interaction". Now if you change the path to some other path that has no permissions issues or such just for testing. Try Shell C:\Book1.xls On a new blank workbook. We need to identify where the issue lies. Either in the file or the location. ;)
Location is working fine, if I write a inexistent file it says it doesn't exist.
Did you test it on an actual new blank workbook?
are u running this in excel vba???
why not directly open the workbook instead of shell!??
Workbooks.Open
Yes, in fact i just wrote that line in a new workbook.
I want to use shell because I'm trying to make a userform that allows you to explore the files contained in a directory and opening them, ot all of them are excel workbooks.
the use ShellEx API
it will make it easier :)
how do I run this instruction?
VB Code:
Private Declare Function ShellEx Lib "shell32.dll" Alias _ "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _ ByVal lpFile As String, ByVal lpParameters As Any, _ ByVal lpDirectory As Any, ByVal nShowCmd As Long) As Long Private Sub Command1_Click() Dim x x = ShellEx(application.Hwnd , "open", "path of file.ext" , "", "", 1) End Sub
oops.. forgot the explanation.. this will open the file with the default app...
so xls will open with excel, txt with notepad (or whatever text editor u have as the default)
etc...
It works just perfect. Any clue of why it didn't work with Shell instruction?
Where or how could I learn to do more advanced things such as using libraries etc...?
I am curious why the Shell didnt work. It should be working.
It doesn't work with Shell because Shell only opens executables. Try:
VB Code:
Shell "notepad.exe"
and it'll work.
zaza
Son of .... Thats it I'm taking a break from VBF for a while. Time for lunch anyways. :lol: