-
ShellExecute Help
Hello, I am having problems with the following statement:
Code:
slAppToRun = ShellExecute(0, vbNullString, "WordPad", App.Path & """\Extension Table.txt""", vbNullString, vbNormalFocus)
This statement works fine if my App.Path is C:\. But when my App.Path is C:\Documents and Settings\Administrator\My Documents\ it doesn't work.
I get a message box from word pad telling me:
C:\Documents
Cannot find this file
Please verify that the correct path and file name are given
Is the error because there are spaces in my path string? How can I correct this?
Thanks very much!
~Steph
-
Re: ShellExecute Help
It has nothing to do with the spaces. All strings use spaces as characters. Any string that you declare can have as many spaces as you want in it.
You have to remember that the ShellExecute has the path set in it as a string called.
Code:
slAppToRun = ShellExecute(0, vbNullString, "WordPad", "Extension Table.txt", App.Path, vbNormalFocus)
-
Re: ShellExecute Help
Hi Steph,
I have got this error before and the reason for this error is using single backslash...
try it this way
Code:
Dim sPath As String
sPath = Replace(App.Path, "\", "\\")
slAppToRun = ShellExecute(0, vbNullString, "WordPad", sPath & """\\Extension Table.txt""", vbNullString, vbNormalFocus)
hope this helps
--Shuja
Edit:
Corrected the code....Sorry for that..oops
-
Re: ShellExecute Help
Question vb_the_best,
The path/directory of the file you are trying to execute is right in the API call itself. Why not just put it there instead of putting it in the file string call in the API call? Why not just do my solution which requires no string combinations and follows the API's primary usage???
Code:
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
-
Re: ShellExecute Help
Hi Peejavery,
Nothing wrong with your code, I was just showing the other way of doing it..
There can be hundered different ways of doing a single thing.. so people give different solutions...
Shuja