Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

ShellExecute

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave Unger - 16 May 2008 01:43 GMT
Hello,

Running XP pro & Excel 2007

I was running this bit of code this morning to launch a shortcut on
the desktop, and everything was working fine.  While experimenting
with variations things went into "lala land", and now I can't get it
to work again (with the original code).  Reinstalling Excel didn't
help. It looks like it's going to launch the shortcut (mometary
hourglass), but the window never opens.  Interestingly, it will still
launch a .bat file without any problem.  My experience with API calls
is limited, any help would be most appreciated.

regards,

DaveU

Sub LaunchLNK()
   Dim DeskTop As String
   DeskTop =
CreateObject("WScript.Shell").SpecialFolders.Item("Desktop")
   ShellExecute 0, "Open", DeskTop & "\myfile.lnk", "", "C:\", 1
End Sub
Gary''s Student - 16 May 2008 02:21 GMT
Hi Dave:

Shell is usually not useful to start a file without specfying the app.  But
rather than using the ShellExecute API, you can still use Shell as in this
example:

Sub Macrosh()
x = Shell("cmd.exe /c C:\start.lnk", 1)
End SuB

This will start an app/file associated with the shortcut on C: folder.

That is because cmd.exe is smart enough to:
1. look at the shortcut
2. find the target file
3. pick the correct app
4. open the file
Signature

Gary''s Student - gsnu2007h

> Hello,
>
[quoted text clipped - 19 lines]
>     ShellExecute 0, "Open", DeskTop & "\myfile.lnk", "", "C:\", 1
> End Sub
Dave Unger - 16 May 2008 04:50 GMT
Hi Gary's Student,

Thanks for your reply.  This isn't working for me either, but maybe I
can see what's happening now (although I don't know why).  The cmd
window flashes opens and immediately closes without running the file.
I think this was happening with my original routine, just too fast to
see.  I tried this with Excel 97 as well (same machine), with the same
results.  I'm starting to wonder if it might be a registry problem.
Anu other suggestions?

regards,

DaveU

On May 15, 7:21 pm, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> Hi Dave:
>
[quoted text clipped - 15 lines]
> --
> Gary''s Student - gsnu2007h
Rick Rothstein (MVP - VB) - 16 May 2008 05:12 GMT
Try it this way...

Sub Macrosh()
  x = Shell("cmd.exe /k C:\start.lnk", 1)
End Sub

I changed the /c to /k... doing that should keep the Command window open so
you can read any error messages that might have been generated. Knowing what
the error is (assuming there is one) should give you a hint at what you will
need to change.

Rick

Hi Gary's Student,

Thanks for your reply.  This isn't working for me either, but maybe I
can see what's happening now (although I don't know why).  The cmd
window flashes opens and immediately closes without running the file.
I think this was happening with my original routine, just too fast to
see.  I tried this with Excel 97 as well (same machine), with the same
results.  I'm starting to wonder if it might be a registry problem.
Anu other suggestions?

regards,

DaveU

On May 15, 7:21 pm, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> Hi Dave:
>
[quoted text clipped - 15 lines]
> --
> Gary''s Student - gsnu2007h
Dave Unger - 16 May 2008 05:31 GMT
Hi Rick,

Thanks- actually I just this minute discoverd that for myself.  I
hardly ever use cmd.exe (obvious), took me a little while before the
light dawned.  After invoking the k switch, it became apparent that
there was an error in the path name.

I really appreciate your help.

regards,
Dave

On May 15, 10:12 pm, "Rick Rothstein \(MVP - VB\)"
<rick.newsNO.S...@NO.SPAMverizon.net> wrote:
> Try it this way...
>
[quoted text clipped - 8 lines]
>
> Rick
Gary''s Student - 16 May 2008 10:31 GMT
Very nice debugging technique.
Signature

Gary''s Student - gsnu200786

> Try it this way...
>
[quoted text clipped - 44 lines]
> > --
> > Gary''s Student - gsnu2007h
Dave Unger - 18 May 2008 04:18 GMT
Thanks for your help Gary''s Student

regards,

DaveU

> Very nice debugging technique.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.