Change Icon of a Shortcut with VBA?

  • Thread starter Thread starter Walt Weber
  • Start date Start date
W

Walt Weber

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
 
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
 
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: Spreadsheet Design &
Automation Co."
.WorkingDirectory = ThisWorkbook.Path
.Save
End With
End With
End Sub
 
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: Spreadsheet Design &
Automation Co."
.WorkingDirectory = ThisWorkbook.Path
.Save
End With
End With
End Sub
 
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: Spreadsheet Design &
Automation Co."
.WorkingDirectory = ThisWorkbook.Path
.Save
End With
End With
End Sub
 
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
 
Back
Top