Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default ShellExecute

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default ShellExecute

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
--
Gary''s Student - gsnu2007h


"Dave Unger" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default ShellExecute

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
wrote:
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
--
Gary''s Student - gsnu2007h

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default ShellExecute

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


"Dave Unger" wrote in message
...
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
wrote:
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
--
Gary''s Student - gsnu2007h


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default ShellExecute

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\)"
wrote:
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



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default ShellExecute

Very nice debugging technique.
--
Gary''s Student - gsnu200786


"Rick Rothstein (MVP - VB)" wrote:

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


"Dave Unger" wrote in message
...
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
wrote:
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
--
Gary''s Student - gsnu2007h



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default ShellExecute

Thanks for your help Gary''s Student

regards,

DaveU

On May 16, 3:31*am, Gary''s Student wrote:
Very nice debugging technique.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell or shellexecute Riva Mario Excel Programming 1 April 18th 08 01:53 PM
Closing a program which was opened with shellexecute JonT Excel Programming 1 February 27th 08 12:46 PM
Alternative to ShellExecute [email protected] Excel Programming 1 January 28th 08 09:35 PM
Open a file in the same instance with ShellExecute MichDenis Excel Programming 2 April 10th 07 04:16 AM
Shellexecute fails with Excel rapple Excel Programming 0 June 24th 06 04:11 PM


All times are GMT +1. The time now is 05:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"