Solved Create a Shortcut to SharePoint Folder on User's Desktop (1 Viewer)

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
New user setup requirement. They must have a desktop shortcut to a specific folder that opens a SharePoint site using windows explorer.

Here's the code I think should be on the button, that isn't working. Very likely operator error.
Compile error expect =
Code:
Private Sub Command29_Click()
   fnCreateShortcut ("Database_Shortcut", "\\sharepointxxxxxx.com\Files")
End Sub

The Public Function is
Code:
Public Function fnCreateShortcut(strName As String, strAppPath As String, strIconPath As String, strDesc As String)
'https://social.msdn.microsoft.com/Forums/en-US/2e03b9d1-8a0f-44e6-a5fc-6c08a5f05138/creating-shortcuts-in-vba-for-windows-xp-and-7-using-wshshortcut-problems?forum=isvvba
' this function creates a desktop shortcut for any file or folder or application
' You need to reference Windows Script Host Object Mode for the code to work
Dim WshShell, strDesktop, oShellLink
Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
'we first check that the object does not exist already
If (Dir(strfilepath & "\" & strName & ".lnk") = "") Then
    Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & strName & ".lnk") 
    With oShellLink
             .TargetPath = strAppPath
             .WindowStyle = 1
             .Hotkey = "CTRL+W"
             .IconLocation = strIconPath
             .Description = strDesc
             .WorkingDirectory = strDesktop
             .Save
    End With
End If
End Function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:50
Joined
Oct 29, 2018
Messages
21,357
Hi. Can you do it manually? Does it have to be automated? Do they need multiple shortcuts to different folders/libraries?
 

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
It needs to be automated. My users are spread across the country. Setting up their computers has to be done remotely and automated to the maximum extend possible.
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:50
Joined
Sep 21, 2011
Messages
14,041
Nothing to do with function expecting 4 parameters and you are only passing 2?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:50
Joined
Oct 29, 2018
Messages
21,357
It needs to be automated. My users are spread across the country. Setting up their computers has to be done remotely and automated to the maximum extend possible.
Hi. I was just curious; because if the shortcut is to only one specific site, then you should be able to manually create it and then email the shortcut file to the users. Or, you can maybe post it on SharePoint, and they can download it. I was just wondering why use code at all. Just my 2 cents...
 

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
Still getting an error when I add 4 parameters. I've tried without the " ", removed the ( ), added Call in front of the whole string.
Code:
fnCreateShortcut ("Database_Shortcut", "\\sharepointxxxxxx\Files","\\sharepointxxxxxx\Icons\E2E_FE.ico","Database Files")

Nothing to do with function expevting 4 parameters and you are only passing 2?
 
Last edited:

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
Good options and if I can't get this to work, what I'll need to do....

Hi. I was just curious; because if the shortcut is to only one specific site, then you should be able to manually create it and then email the shortcut file to the users. Or, you can maybe post it on SharePoint, and they can download it. I was just wondering why use code at all. Just my 2 cents...
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:50
Joined
Oct 29, 2018
Messages
21,357
Good options and if I can't get this to work, what I'll need to do....
Okay, just as a test, I manually created the attached shortcut to my website. Does it work for you?
 

Attachments

  • My Website.zip
    232 bytes · Views: 246

Gasman

Enthusiastic Amateur
Local time
Today, 13:50
Joined
Sep 21, 2011
Messages
14,041
Good options and if I can't get this to work, what I'll need to do....
I created a shortcut with the correct values and copied that to the user's desktop on the db setup.
Admittedly mine was for the FE DB being used, but the logic should be the same?
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:50
Joined
Sep 21, 2011
Messages
14,041
I have just tested your code.
Firstly your variables are not dimmed correctly, but I just dimmed the str variables as I did not know what the others were.
strFilePath does not exist. Once created and given values I had a shortcut on my desktop albeit without icon as the path for an existing icon in another shortcut is %SystemRoot%\System32\SHELL32.dll. Not sure how to specify a particular icon from within that.

HTH

Edit:
Select icon by it's index number in the file if not an individual ico file?
Code:
strIconPath= "c:\windows\System32\SHELL32.dll" & ",46"
 
Last edited:

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
@Gasman

Can you post the code on both the Public Function and Button that you got to work on your computer?

I don't understand your notes below and what you changed to make it work locally.

Firstly your variables are not dimmed correctly, but I just dimmed the str variables as I did not know what the others were.
 

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
I've got it working. Thanks for the assistance and coaching. The key was making changes to the Public Function as @Gasman recommended. I also like the technique for pulling in icons from the dll.

Code:
Private Sub Command29_Click()
   fnCreateShortcut "Database_Shortcut", "\\sharepoint\Database Files", "c:\windows\System32\SHELL32.dll" & ",46", "Database Files"
End Sub

Code:
Public Function fnCreateShortcut(strName As String, strAppPath As String, strIconPath As String, strDesc As String)
' https://www.access-programmers.co.uk/forums/threads/create-a-shortcut-to-sharepoint-folder-on-users-desktop.310355/#post-1679774
' this function creates a desktop shortcut for any file or folder or application
' You need to reference Windows Script Host Object Mode for the code to work
Dim WshShell, strDesktop, oShellLink
Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Dim strFilePath As String

'we first check that the object does not exist already
If (Dir(strFilePath & "\" & strName & ".lnk") = "") Then
    Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & strName & ".lnk")
    With oShellLink
             .TargetPath = strAppPath
             .WindowStyle = 1
             .Hotkey = "CTRL+W"
             .IconLocation = strIconPath
             .Description = strDesc
             .WorkingDirectory = strDesktop
             .Save
    End With
End If
End Function
 

theDBguy

I’m here to help
Staff member
Local time
Today, 06:50
Joined
Oct 29, 2018
Messages
21,357
I've got it working. Thanks for the assistance and coaching. The key was making changes to the Public Function as @Gasman recommended. I also like the technique for pulling in icons from the dll.

Code:
Private Sub Command29_Click()
   fnCreateShortcut "Database_Shortcut", "\\sharepoint\Database Files", "c:\windows\System32\SHELL32.dll" & ",46", "Database Files"
End Sub

Code:
Public Function fnCreateShortcut(strName As String, strAppPath As String, strIconPath As String, strDesc As String)
' https://www.access-programmers.co.uk/forums/threads/create-a-shortcut-to-sharepoint-folder-on-users-desktop.310355/#post-1679774
' this function creates a desktop shortcut for any file or folder or application
' You need to reference Windows Script Host Object Mode for the code to work
Dim WshShell, strDesktop, oShellLink
Set WshShell = CreateObject("WScript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Dim strFilePath As String

'we first check that the object does not exist already
If (Dir(strFilePath & "\" & strName & ".lnk") = "") Then
    Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & strName & ".lnk")
    With oShellLink
             .TargetPath = strAppPath
             .WindowStyle = 1
             .Hotkey = "CTRL+W"
             .IconLocation = strIconPath
             .Description = strDesc
             .WorkingDirectory = strDesktop
             .Save
    End With
End If
End Function
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
While the code above worked for a couple of people, I just had a new user attempt to create the shortcut and we ended up with icons on the desktop, that were named correctly, BUT no website path populated NOR the image on the icon from the DLL.

The user is using a Windows based computer.

Thoughts on troubleshooting?
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:50
Joined
Sep 21, 2011
Messages
14,041
Create manually to start with. Then work back.
Run the function manually on the user's PC and step through line by line with F8.
 

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
To get the Windows Explorer Folder to open the shortcut needs to use Internet Explorer. I have a new user that uses Mozilla as their default browser which i believe is why the shortcut isn't populating and running correctly. While I need to get the code working, I don't want to force them to change their default browser.

Question: Within the code, can you direct a specific browser (IE) be used? I'm thinking this is where that would need to be modified.

Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & strName & ".lnk")
 

Gasman

Enthusiastic Amateur
Local time
Today, 13:50
Joined
Sep 21, 2011
Messages
14,041
Not really.?

Another user was using

Code:
Shell "C:\WINDOWS\explorer.exe """ & FoldernameDestFIRE & "", vbNormalFocus
 

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
Working on my computer. Will have the other user test it out. Thanks.

Here's the updated code

Code:
Option Compare Database
Option Explicit

Public Function fnCreateShortcut(strName As String, strAppPath As String, strIconPath As String, strDesc As String)
    ' https://www.access-programmers.co.uk/forums/threads/create-a-shortcut-to-sharepoint-folder-on-users-desktop.310355/#post-1679774
    ' https://help4windows.com/windows_7_shell32_dll.shtml
    ' this function creates a desktop shortcut for any file or folder or application
    ' You need to reference Windows Script Host Object Mode for the code to work
    Dim WshShell, strDesktop, oShellLink
    Set WshShell = CreateObject("WScript.Shell")
    strDesktop = WshShell.SpecialFolders("Desktop")
    Dim strFilePath As String
    Shell "C:\WINDOWS\explorer.exe """ & strAppPath & "", vbNormalFocus
    
    'we first check that the object does not exist already
    If (Dir(strFilePath & "\" & strName & ".lnk") = "") Then
        Set oShellLink = WshShell.CreateShortcut(strDesktop & "\" & strName & ".lnk")
        With oShellLink
            .TargetPath = strAppPath
            .WindowStyle = 1
            .Hotkey = "CTRL+W"
            .IconLocation = strIconPath
            .Description = strDesc
            .WorkingDirectory = strDesktop
            .Save
        End With
    End If
End Function

No change to the code on the button.
 

dgreen

Member
Local time
Today, 08:50
Joined
Sep 30, 2018
Messages
397
Confirmed with the modified code that this now works on a computer who's default web browser isn't IE. Thank you very much for getting this improvement rolled out.
 

Users who are viewing this thread

Top Bottom