![]() |
Changing Display Icon
Is there a way either through VBA or a Windows API call to change the display
icon of a shortcut located on the desktop? -- When you lose your mind, you free your life. Ever Notice how we use '' for comments in our posts even if they aren''t expected to go into the code? |
Changing Display Icon
ben,
It can be done with the "WScript.Shell" object. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Sub ChangeLnkIcon() ' Changes icon for desktop shortcut named TestA to the 21st icon in shell32 Set wsh = CreateObject("WScript.Shell") strDesktop = wsh.SpecialFolders("Desktop") Set objLink = wsh.CreateShortcut(strDesktop & "\TestA.lnk") With objLink .IconLocation = "%SystemRoot%\system32\SHELL32.dll, 20" .Save End With End Sub _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Even though you would not see the lnk extension on the shortcut name (TestA in my example),you need to include the LNK extension. If no shortcut named TestA were found on the desktop, a new shortcut with that name (and no Target) would be created. The .Save is required to create a new shortcut or to save edits, otherwise CreateShortcut simply makes the various properties like IconLocation available for reading. Steve Yandl "ben" (remove this if mailing direct) wrote in message ... Is there a way either through VBA or a Windows API call to change the display icon of a shortcut located on the desktop? -- When you lose your mind, you free your life. Ever Notice how we use '' for comments in our posts even if they aren''t expected to go into the code? |
Changing Display Icon
steve is it possible to use this method using a custom .ico file?
-- When you lose your mind, you free your life. Ever Notice how we use '' for comments in our posts even if they aren''t expected to go into the code? "Steve Yandl" wrote: ben, It can be done with the "WScript.Shell" object. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Sub ChangeLnkIcon() ' Changes icon for desktop shortcut named TestA to the 21st icon in shell32 Set wsh = CreateObject("WScript.Shell") strDesktop = wsh.SpecialFolders("Desktop") Set objLink = wsh.CreateShortcut(strDesktop & "\TestA.lnk") With objLink .IconLocation = "%SystemRoot%\system32\SHELL32.dll, 20" .Save End With End Sub _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Even though you would not see the lnk extension on the shortcut name (TestA in my example),you need to include the LNK extension. If no shortcut named TestA were found on the desktop, a new shortcut with that name (and no Target) would be created. The .Save is required to create a new shortcut or to save edits, otherwise CreateShortcut simply makes the various properties like IconLocation available for reading. Steve Yandl "ben" (remove this if mailing direct) wrote in message ... Is there a way either through VBA or a Windows API call to change the display icon of a shortcut located on the desktop? -- When you lose your mind, you free your life. Ever Notice how we use '' for comments in our posts even if they aren''t expected to go into the code? |
Changing Display Icon
Yes, just point to the ico file, skip the comma and index number and don't
forget the quotes around the path. Steve "ben" (remove this if mailing direct) wrote in message ... steve is it possible to use this method using a custom .ico file? -- When you lose your mind, you free your life. Ever Notice how we use '' for comments in our posts even if they aren''t expected to go into the code? "Steve Yandl" wrote: ben, It can be done with the "WScript.Shell" object. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Sub ChangeLnkIcon() ' Changes icon for desktop shortcut named TestA to the 21st icon in shell32 Set wsh = CreateObject("WScript.Shell") strDesktop = wsh.SpecialFolders("Desktop") Set objLink = wsh.CreateShortcut(strDesktop & "\TestA.lnk") With objLink .IconLocation = "%SystemRoot%\system32\SHELL32.dll, 20" .Save End With End Sub _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Even though you would not see the lnk extension on the shortcut name (TestA in my example),you need to include the LNK extension. If no shortcut named TestA were found on the desktop, a new shortcut with that name (and no Target) would be created. The .Save is required to create a new shortcut or to save edits, otherwise CreateShortcut simply makes the various properties like IconLocation available for reading. Steve Yandl "ben" (remove this if mailing direct) wrote in message ... Is there a way either through VBA or a Windows API call to change the display icon of a shortcut located on the desktop? -- When you lose your mind, you free your life. Ever Notice how we use '' for comments in our posts even if they aren''t expected to go into the code? |
All times are GMT +1. The time now is 05:00 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com