View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Walt Weber[_2_] Walt Weber[_2_] is offline
external usenet poster
 
Posts: 24
Default Change Icon of a Shortcut with VBA?

Hi Michel,

That last transmisssion shouldn't have been sent. Please
read this one.

Thank you - your response works!

I don't quite understand why or how. I've modified it to:
Sub MakeShortcut()
With CreateObject("WScript.Shell")
With _
.CreateShortcut(.SpecialFolders("Desktop")
& "\MRS.lnk")
.TargetPath = ThisWorkbook.Path & "\" &
ThisWorkbook.Name
.WindowStyle = 1
.Hotkey = ""
.IconLocation = ThisWorkbook.Path
& "\Icon.ico, 0"
.Description = "by: Walt"
.WorkingDirectory = ThisWorkbook.Path
.Save
End With
End With
End Sub

Why doesn't it crash when there's an existing .ico file
with that name (You can run this routine multiple times
with no conflict)? Furthermore, your response did not
address whether it's possible or practical to change or
replace all shortcut icons pointed to the same file. Is
it? You're the master in this area - not me.

Best Regards,
Walt


-----Original Message-----
Hi Walt;
You can recreate it by changing the name of the file

icon; one example:

With CreateObject("WScript.Shell")
With .CreateShortcut(.SpecialFolders("Desktop")

& "\Gpao.lnk")
.TargetPath = ThisWorkbook.Path & "\Gpao.vbe"
.WindowStyle = 1
.Hotkey = "CTRL+SHIFT+G"
.IconLocation = ThisWorkbook.Path & "\Gpao.ico, 0"
.Description = "Session GPAO"
.WorkingDirectory = ThisWorkbook.Path
.Save
End With
End With

MP

"Walt Weber" a écrit dans le message de
...
Hi To All,

Is it possible to change the icon of a desktop shortcut
using VBA? And also using VBA, can you search for and
identify the shortcut to change using it's target path?

Any help appreciated.

Walt



.