How to Pin Website to Windows taskbar

GautamAXA

New Member
Joined
Jun 9, 2015
Messages
1
Hi

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

Code:
   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 = "http://www.msn.com"

  oUrlLink.Save

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"
    Else
        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.
    lnk.Save

    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"
        Else
            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
                Next
            End If
        Next
        '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?

regards
Gautam
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

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 MrExcel.com.
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 "mrexcel.com".
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
Back
Top