Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Create Shortcut on desctop

193 views
Skip to first unread message

Ludo Soete

unread,
Jul 16, 2002, 2:42:53 AM7/16/02
to
Hi,

Is it possible to create a shortcut with VBA that is placed on the
desctop with a custom icon (shortcut point to an .XLS file)? If so,
how can this be done.


Thanks
Ludo

William

unread,
Jul 16, 2002, 3:10:46 AM7/16/02
to
Hi Ludo

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
--

Regards

William
willw...@yahoo.com


"Ludo Soete" <bart.l...@barco.com> wrote in message
news:33cb9434.02071...@posting.google.com...

Ludo Soete

unread,
Jul 17, 2002, 12:01:45 AM7/17/02
to
"William" <willw...@yahoo.com> wrote in message news:<eHjAEfJLCHA.2588@tkmsftngp09>...

> Hi Ludo
>
> 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
> --
>
Thanks William, but i would like to place a CUSTOM icon on my desktop,
so i guess that i have to add one more line VBA code between 'With
MyShortcut' & 'End With'. I don't know the syntax for it because
adding a line like '.Picture="IconPath\Icon.ICO' doesn't work. I get a
message like ' Object doesn't support this property or method'.
Any idea what the syntax for a custom icon is?

Where can i get some more information abouth this subject?

Thanks a lot.
Ludo

Rob Bruce

unread,
Jul 17, 2002, 6:07:35 AM7/17/02
to
Hi Ludo,

There's some code on my site at

http://www.rb-ad.dircon.co.uk/rob/excelvba/develop/index.htm

Be aware that MS has broken binary compatibility for the Windows Script
Host, so the code may not work on your version of Windows. The solution is
to get rid of the reference to the WSH, change all WSH object declarations
to type generic Object, and then create the WSH instance as William did:

Set WSHShell = CreateObject("WScript.Shell")

...rather that by using the New keyword.

HTH

--
Rob

Excel VBA Programming Stuff:
www.analytical-dynamics.co.uk/

Please keep conversations in the newsgroup so that all may contribute and
benefit.

0 new messages