ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Change Icon of a Shortcut with VBA? (https://www.excelbanter.com/excel-programming/297400-change-icon-shortcut-vba.html)

Walt Weber[_2_]

Change Icon of a Shortcut with VBA?
 
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

Michel Pierron[_2_]

Change Icon of a Shortcut with VBA?
 
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




No Name

Change Icon of a Shortcut with VBA?
 
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



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



.


No Name

Change Icon of a Shortcut with VBA?
 
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



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



.


No Name

Change Icon of a Shortcut with VBA?
 
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



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



.


Walt Weber[_2_]

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



.



All times are GMT +1. The time now is 10:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com