Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I use Shell to open just a folder or run a shortcut?

Status
Not open for further replies.

tedsmith

Programmer
Nov 23, 2000
1,762
AU
I have tried Shell in my app to do 2 things without success
1. Open just a folder eg Shell ("C:\Myfolder",vbNormalFocus)
2. Open a vnc shortcut to start VNC viewer to remote desktop to another computer eg Shell ("c:\VNCFolder\10.208.9.123.vnc",vbNormalFocus). "10.208.9.123.vnc" is a shortcut to opening the remote desktop on the required computer and appears to be an ini type file.

Both the statements within the ( ) do the desired thing when entered in the Windows Explorer address box.

What am I doing wrong?
 
> do the desired thing when entered in the Windows Explorer address box

So try;

Shell "Explorer C:\MyFolder", vbNormalFocus

etc.
 
I found an old answer in thread222-749475
Sorry I should have looked first!
 
The Shell command does not do what you think it does. Specifically, as per the documentation, it runs an executable program. In neither case are you passing it the name of an executable program. Here, have 3 short examp0les of variants that should work:

Code:
[blue]
Option Explicit

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

[green]' These are actually examples of the original API versions of the VBAppWinStyle enumeration[/green]
Private Const SW_MAXIMIZE = 3 [green]' vbMaximizedFocus[/green]
Private Const SW_MINIMIZE = 6 [green]' vbMinimizedNoFocus[/green]
Private Const SW_SHOWNORMAL = 1 [green]'vbNormalFocuc[/green]

Public Sub spoon()
    ShellExecute 0&, "open", "C:\temp", vbNullString, vbNullString, SW_SHOWNORMAL
End Sub

Public Sub wombat()
    Shell "rundll32.exe url.dll,FileProtocolHandler C:\temp", vbNormalFocus
End Sub


Public Sub mike()
    CreateObject("Shell.application").ShellExecute "c:\temp", , , , SW_SHOWNORMAL
End Sub[/blue]
 
Thanks/ I used the Shellexecute OK but the only problem is that if the shortcut is missing it doesn't show any file missing warning (like shell does with a file) - just nothing happens.
 
Code:
    Const ssfDesktop = 0
    Dim FolderItem As Object
    
    With CreateObject("Shell.Application").NameSpace(ssfDesktop)
        On Error Resume Next
        FolderItem = .ParseName("c:\temp\fudd.dud")
        If Err Then
            MsgBox "No such file"
        Else
            FolderItem.InvokeVerb
        End If
        On Error GoTo 0
    End With

Also works back to earlier Shell versions (Win98, Win95+Desktop Update, etc.).
 
Thanks
However I simply used the return value of Shellexecute
The remote desktop 'shortcut' is in the form of "MyIPAddress.vnc"
Code:
  w = ShellExecute(hwnd, "open", "c:\VNCInfo\" & MyIPAddress & ".vnc", vbNullString, vbNullString, SW_SHOWNORMAL)
    Select Case w
        Case 2
            MsgBox "VNC Shortcut for stop" & MyIPAddress & vbCr & "is not in the c:\VNCInfo\ folder.", vbCritical, "No File Found"
        Case Is > 31
            'OK
        Case Else
            'Other error
            MsgBox "VNC may not be installed or set up correctly" & vbCr & "Try direct VNC connection to the stop IP address.", vbCritical, "No VNC"
    End Select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top