Roger
asked on
Customise excel icon in taskbar on loading. I have half a solution, but need to know how to implement a VBS script to automate icon Pin/Unpin on Task Bar
On Windows7 operating system, I wish instances of myExcelProject.xlsm to have a distinctive icon in the task bar. This will distinguish my project from other excel files. My test icon graphic ( tstTaskBarIcon2.ico) is simply a green square. However, it has been uploaded with a 'make believe' jpg extension because an .ico extension is not accepted by the EE upload site. Nevertheless, this tstTaskBarIcon2.jpg IS in reality an .ico file, so if you need to open it, please EDIT the extension back to .ico.
I first used code in: http://stackoverflow.com/questions/20142765/how-to-change-the-excel-icon-in-taskbar-while-loading (which is the attached file: myExcelProject.xlsm). When initiated from ThisWorkbook.Workbook_Open , this code customised the icon that appears in the Task bar window THUMB NAIL file illustration, but the code did NOT customise the icon in the Taskbar TRAY. However,..
.. 'pinning' and then 'unpinning' the ison in the Task bar TRAY DID cause the customised 'GREEN' icon to be displayed reliably, and exclusively for myExcelProject, and not for other xl files. Pinning/unpinning is required each time the file is opened. So, unless there is an alternative, I needed to automate 'pinning' and then 'unpinning'.
I found this code (copies at foot of this text):
http://www.codeproject.com/Articles/185512/Programmatically-PIN-shortcut-onto-Taskbar-on-Win
It is written in VBS script, and the file to be pinned/unpinned is:
LnkFile = Desktop.Self.Path&"\Schedu leNotifier .lnk"
I dont know VBS..
Do I run these scripts from Windows shell (which is new to me)?
Some pointers would be appreciated
Thanks
Kelvin
----FYI copied from: http://www.codeproject.com/Articles/185512/Programmatically-PIN-shortcut-onto-Taskbar-on-Win--
--------------- Pin to Taskbar ----------------
Option Explicit
'Const CSIDL_COMMON_PROGRAMS = &H17
Dim ShellApp, FSO, Desktop
Set ShellApp = CreateObject("Shell.Applic ation")
Set FSO = CreateObject("Scripting.Fi leSystemOb ject")
'Set StartMenuFolder = ShellApp.NameSpace(CSIDL_C OMMON_PROG RAMS)
Set Desktop = ShellApp.NameSpace("C:\Use rs\Wayne\D esktop")
Dim LnkFile
LnkFile = Desktop.Self.Path&"\Schedu leNotifier .lnk"
If(FSO.FileExists(LnkFile) ) Then
Dim tmp, verb
'For Each verb in Desktop.ParseName("Schedul eNotifier. lnk").Verb s
'tmp = tmp&verb&chr(13)
'Next
'MsgBox(tmp)
Dim desktopImtes, item
Set desktopImtes = Desktop.Items()
For Each item in desktopImtes
If (item.Name = "ScheduleNotifier") Then
'MsgBox(item.Name)
For Each verb in item.Verbs
If (verb.Name = "Pin to Tas&kbar") _
Then 'If (verb.Name = "锁定到任务栏(&K)")
verb.DoIt
End If
Next
End If
Next
End If
Set FSO = Nothing
Set ShellApp = Nothing
--------------- Unpin from Taskbar---------------
Option Explicit
'Const CSIDL_COMMON_PROGRAMS = &H17
Dim ShellApp, FSO, Desktop
Set ShellApp = CreateObject("Shell.Applic ation")
Set FSO = CreateObject("Scripting.Fi leSystemOb ject")
'Set StartMenuFolder = ShellApp.NameSpace(CSIDL_C OMMON_PROG RAMS)
Set Desktop = ShellApp.NameSpace("C:\Use rs\Wayne\D esktop")
Dim LnkFile
LnkFile = Desktop.Self.Path&"\Schedu leNotifier .lnk"
If(FSO.FileExists(LnkFile) ) Then
Dim tmp, verb
'For Each verb in Desktop.ParseName("Schedul eNotifier. lnk").Verb s
'tmp = tmp&verb&chr(13)
'Next
'MsgBox(tmp)
Dim desktopImtes, item
Set desktopImtes = Desktop.Items()
For Each item in desktopImtes
If (item.Name = "ScheduleNotifier") Then
'MsgBox(item.Name)
For Each verb in item.Verbs
If (verb.Name = "Unpin from Tas&kbar") _
Then 'If (verb.Name = "从任务栏脱离(&K)")
verb.DoIt
End If
Next
End If
Next
End If
Set FSO = Nothing
Set ShellApp = Nothing
myExcelProject.xlsm
tstTaskBarIcon2.jpg
I first used code in: http://stackoverflow.com/questions/20142765/how-to-change-the-excel-icon-in-taskbar-while-loading (which is the attached file: myExcelProject.xlsm). When initiated from ThisWorkbook.Workbook_Open
.. 'pinning' and then 'unpinning' the ison in the Task bar TRAY DID cause the customised 'GREEN' icon to be displayed reliably, and exclusively for myExcelProject, and not for other xl files. Pinning/unpinning is required each time the file is opened. So, unless there is an alternative, I needed to automate 'pinning' and then 'unpinning'.
I found this code (copies at foot of this text):
http://www.codeproject.com/Articles/185512/Programmatically-PIN-shortcut-onto-Taskbar-on-Win
It is written in VBS script, and the file to be pinned/unpinned is:
LnkFile = Desktop.Self.Path&"\Schedu
I dont know VBS..
Do I run these scripts from Windows shell (which is new to me)?
Some pointers would be appreciated
Thanks
Kelvin
----FYI copied from: http://www.codeproject.com/Articles/185512/Programmatically-PIN-shortcut-onto-Taskbar-on-Win--
--------------- Pin to Taskbar ----------------
Option Explicit
'Const CSIDL_COMMON_PROGRAMS = &H17
Dim ShellApp, FSO, Desktop
Set ShellApp = CreateObject("Shell.Applic
Set FSO = CreateObject("Scripting.Fi
'Set StartMenuFolder = ShellApp.NameSpace(CSIDL_C
Set Desktop = ShellApp.NameSpace("C:\Use
Dim LnkFile
LnkFile = Desktop.Self.Path&"\Schedu
If(FSO.FileExists(LnkFile)
Dim tmp, verb
'For Each verb in Desktop.ParseName("Schedul
'tmp = tmp&verb&chr(13)
'Next
'MsgBox(tmp)
Dim desktopImtes, item
Set desktopImtes = Desktop.Items()
For Each item in desktopImtes
If (item.Name = "ScheduleNotifier") Then
'MsgBox(item.Name)
For Each verb in item.Verbs
If (verb.Name = "Pin to Tas&kbar") _
Then 'If (verb.Name = "锁定到任务栏(&K)")
verb.DoIt
End If
Next
End If
Next
End If
Set FSO = Nothing
Set ShellApp = Nothing
--------------- Unpin from Taskbar---------------
Option Explicit
'Const CSIDL_COMMON_PROGRAMS = &H17
Dim ShellApp, FSO, Desktop
Set ShellApp = CreateObject("Shell.Applic
Set FSO = CreateObject("Scripting.Fi
'Set StartMenuFolder = ShellApp.NameSpace(CSIDL_C
Set Desktop = ShellApp.NameSpace("C:\Use
Dim LnkFile
LnkFile = Desktop.Self.Path&"\Schedu
If(FSO.FileExists(LnkFile)
Dim tmp, verb
'For Each verb in Desktop.ParseName("Schedul
'tmp = tmp&verb&chr(13)
'Next
'MsgBox(tmp)
Dim desktopImtes, item
Set desktopImtes = Desktop.Items()
For Each item in desktopImtes
If (item.Name = "ScheduleNotifier") Then
'MsgBox(item.Name)
For Each verb in item.Verbs
If (verb.Name = "Unpin from Tas&kbar") _
Then 'If (verb.Name = "从任务栏脱离(&K)")
verb.DoIt
End If
Next
End If
Next
End If
Set FSO = Nothing
Set ShellApp = Nothing
myExcelProject.xlsm
tstTaskBarIcon2.jpg
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Kelvin