Add shortcut icon to a users desktop?

G

Guest

Using Office 2003 and Windows XP.

Is it possible to copy a file to a user's desktop folder and then add a
shortcut icon to the file to that user's desktop?

If so, could someone please post example VBA code to do this? It would solve
my deployment issues for a program...
 
R

Ron de Bruin

Hi XP

You can find code here to find the path of the desktop
http://www.rondebruin.nl/folder.htm#SpecialFolders


To create a shortcut to the activeworkbook try

Sub Desktopshortcut()
Dim WSHShell As Object
Dim MyShortcut As Object
Dim DesktopPath As String
Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\" & _
ActiveWorkbook.Name & ".lnk")
With MyShortcut
.TargetPath = ActiveWorkbook.FullName
.Save
End With
Set WSHShell = Nothing
MsgBox "A shortcut has been placed on your desktop."
End Sub
 
B

Bernie Deitrick

Larry,

See macros below.

HTH,
Bernie
MS Excel MVP

Sub CreateDesktopShortcut()
Dim WSHShell As Object
Dim MyShortcut As Object
Dim DesktopPath As String
Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\" & _
ActiveWorkbook.Name & ".lnk")
With MyShortcut
.TargetPath = ActiveWorkbook.FullName
.Save
End With
Set WSHShell = Nothing
MsgBox "A shortcut has been placed on your desktop."
End Sub

Sub DeleteDesktopShortcut()
Dim WSHShell As Object
Dim MyShortcut As Object
Dim DesktopPath As String
Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
On Error GoTo NotFound
Kill (DesktopPath & "\" & ActiveWorkbook.Name & ".lnk")
MsgBox "A shortcut has been removed from your desktop."
Set WSHShell = Nothing
Exit Sub
NotFound:
MsgBox "A shortcut to the active workbook was not found on your desktop."
Set WSHShell = Nothing
End Sub
 
L

Larry

Thank you.
--
Larry


Bernie Deitrick said:
Larry,

See macros below.

HTH,
Bernie
MS Excel MVP

Sub CreateDesktopShortcut()
Dim WSHShell As Object
Dim MyShortcut As Object
Dim DesktopPath As String
Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
Set MyShortcut = WSHShell.CreateShortcut(DesktopPath & "\" & _
ActiveWorkbook.Name & ".lnk")
With MyShortcut
.TargetPath = ActiveWorkbook.FullName
.Save
End With
Set WSHShell = Nothing
MsgBox "A shortcut has been placed on your desktop."
End Sub

Sub DeleteDesktopShortcut()
Dim WSHShell As Object
Dim MyShortcut As Object
Dim DesktopPath As String
Set WSHShell = CreateObject("WScript.Shell")
DesktopPath = WSHShell.SpecialFolders("Desktop")
On Error GoTo NotFound
Kill (DesktopPath & "\" & ActiveWorkbook.Name & ".lnk")
MsgBox "A shortcut has been removed from your desktop."
Set WSHShell = Nothing
Exit Sub
NotFound:
MsgBox "A shortcut to the active workbook was not found on your desktop."
Set WSHShell = Nothing
End Sub






.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top