Creating Shell Shortcuts

Windows Scripting Host has a Shell object that gives access to Windows shell. The Shell object provides methods for creating the Shell Shortcuts. The CreateShellShortcut() VBA function shows how to use the Shell object to create the Shell Shortcuts:

'
' CreateShellShortcut()
'
' TargetName - The file that would be launched when the shortcut is clicked.
' TargetArguments - Command line parameters to TargetName.
' TargetDescription - The description of the shortcut.
' ShortcutFileName - The shortcut file name including the .lnk extension.
'
' Copyright (C) 2002 OfficeOne
'
Sub CreateShellShortcut(ByVal TargetName As String, _
    ByVal TargetArguments As String, _
    ByVal TargetDescription As String, _
    ByVal ShortcutFileName As String)

    Dim WSH As Object
    Dim Shortcut As Object

    Set WSH = CreateObject("WScript.Shell")
    Set Shortcut = WSH.CreateShortcut(ShortcutFileName)
    With Shortcut
        .TargetPath = TargetName
        .Arguments = TargetArguments
        .Description = TargetDescription
        .Save
    End With
    Set Shortcut = Nothing
    Set WSH = Nothing
End Sub

The following function demonstrates how to call CreateShellShortcut(): 

Sub TestShortcut()
    CreateShellShortcut "c:\test.pps", "", "Just a test", "c:\test.lnk"
End Sub

Contact OfficeOne on email at officeone@officeoneonline.com. Copyright © 2001-2023 OfficeOne. All rights reserved.