Tuesday, June 15, 2010

Creating desktop shortcut using VBA - MS Excel

Creating Desktop Shortcut:


Sub CreateShortCut() 
    Dim oWSH As Object 
    Dim oShortcut As Object 
    Dim sPathDeskTop As String 
     
    Set oWSH = CreateObject("WScript.Shell") 
    sPathDeskTop = oWSH.SpecialFolders("Desktop") 
     
    Set oShortcut = oWSH.CreateShortCut(sPathDeskTop & "\" & _ 
    ActiveWorkbook.Name & ".lnk") 
    With oShortcut 
        .TargetPath = ActiveWorkbook.FullName 
        .Save 
    End With 
    Set oWSH = Nothing 
     
End Sub 

No comments:

Post a Comment