Link to home
Start Free TrialLog in
Avatar of Roger
RogerFlag for United Kingdom of Great Britain and Northern Ireland

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&"\ScheduleNotifier.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.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")

'Set StartMenuFolder = ShellApp.NameSpace(CSIDL_COMMON_PROGRAMS)
Set Desktop =  ShellApp.NameSpace("C:\Users\Wayne\Desktop")

Dim LnkFile
LnkFile = Desktop.Self.Path&"\ScheduleNotifier.lnk"

If(FSO.FileExists(LnkFile)) Then
    Dim tmp, verb
    'For Each verb in Desktop.ParseName("ScheduleNotifier.lnk").Verbs
        '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.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")

'Set StartMenuFolder = ShellApp.NameSpace(CSIDL_COMMON_PROGRAMS)
Set Desktop =  ShellApp.NameSpace("C:\Users\Wayne\Desktop")

Dim LnkFile
LnkFile = Desktop.Self.Path&"\ScheduleNotifier.lnk"

If(FSO.FileExists(LnkFile)) Then
    Dim tmp, verb
    'For Each verb in Desktop.ParseName("ScheduleNotifier.lnk").Verbs
        '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
Avatar of Randy Downs
Randy Downs
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roger

ASKER

Many thanks for exactly the kind of advice and background information I was seeking.
Kelvin