How to Pin Website to Windows taskbar


New Member
Jun 9, 2015

My requirement is to pinning webpage to task bar. My code is as follows

   Sub CreateShortcut()

  Set WshShell = CreateObject("WScript.Shell")
  'strDesktop = WshShell.SpecialFolders("Desktop")
  strDesktop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
  Set oUrlLink = WshShell.CreateShortcut(strDesktop & "\msn.lnk")
  oUrlLink.TargetPath = ""


End Sub

  Public Sub PinApplicationToTaskBar(AppPathAndName, ShortcutName, OnStartMenu)
    'This is on for a soft failure. Uncomment this if error checking for a hard failure is needed for debugging.
    On Error Resume Next

    Dim FileSystemObj, ObjShell, ObjShellApp
    Set ObjShell = CreateObject("WScript.Shell")
    ObjShell.popup ("Hi")
    Set FileSystemObj = CreateObject("Scripting.FileSystemObject")

    'Create a temp location for the short-cut to exist
    TempShortcutLocation = FileSystemObj.GetFolder(ObjShell.ExpandEnvironmentStrings("%TEMP%"))
    'Where is it being pinned?  Determine the location where the pinned item will reside
    If (Trim(LCase(OnStartMenu)) = "true") Then ' pinned to start menu
        HasAlreadyBeenPinnedShortCut = ObjShell.ExpandEnvironmentStrings("%APPDATA%") & _
        "\Microsoft\Internet Explorer\Quick Launch\User Pinned\StartMenu"
        HasAlreadyBeenPinnedShortCut = ObjShell.ExpandEnvironmentStrings("%APPDATA%") & _
        "\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"

    End If
    'Temporary location for the application short-cut
    TempShortcut = TempShortcutLocation & "\" & ShortcutName & ".lnk"
    'Possible location of a pinned item
    HasAlreadyBeenPinnedShortCut = HasAlreadyBeenPinnedShortCut & "\" & ShortcutName & ".lnk"

    'If this already exists, than exit this procedure. The application has already been pinned.
    If (FileSystemObj.FileExists(HasAlreadyBeenPinnedShortCut)) Then
        'MsgBox(HasAlreadyBeenPinnedShortCut & " Already Pinned")
        Exit Sub
    End If
    'Create a short-cut using the shell
    Set lnk = ObjShell.CreateShortcut(TempShortcut)
    lnk.TargetPath = AppPathAndName ' Full application path and name
    lnk.Arguments = ""
    lnk.Description = ShortcutName 'The name that appears on the start menu.

    Set ObjShellApp = CreateObject("Shell.Application")

    'Get the newly created short-cut full path
    Set ShortCutToPin = ObjShellApp.Namespace(TempShortcutLocation)

    If (FileSystemObj.FileExists(TempShortcut)) Then
        Dim ShortCutToPinItem, verb
        'Set the location to pin the item to do based on the passed OnStartMenu argument
        If (Trim(LCase(OnStartMenu)) = "true") Then
            verbToDo = "Pin to Start Men&u"
            verbToDo = "Pin to Tas&kbar"
        End If
        For Each ShortCutToPinItem In ShortCutToPin.Items()
            'Look for the pinning verb when the temporary short-cut name matches the passed ShortcutName argument
            If (ShortCutToPinItem.Name = ShortcutName) Then
                'Loop through the shell object's (the short-cut) commands looking for the pinning method.
                For Each verb In ShortCutToPinItem.Verbs
                    'The verb matches the verbToDo so pin it to verb's defined location
                    If (verb.Name = verbToDo) Then verb.DoIt
            End If
        'Delete the temporary short-cut used to pin the application
        FileSystemObj.DeleteFile (TempShortcut)
    End If
    'clean up
    Set ObjShell = Nothing
    Set FileSystemObj = Nothing
    Set ObjShellApp = Nothing
End Sub

Above function is working fine if i try with
Call PinApplicationToTaskBar("C:\Program Files (x86)\Notepad++.exe", "Notepad", "false")

But if i try with the following(saving a webpage)
Call PinApplicationToTaskBar("C:\Users\<User Name>\Desktop\msn.url", "msn", "false")

Outcome is not as expected.

Could any one suggest me the wayout?


Some videos you may like

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Watch MrExcel Video

Forum statistics

Latest member

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back