Consulting

Results 1 to 3 of 3

Thread: How to login to SharePoint using VBA

  1. #1
    VBAX Newbie
    Joined
    Jun 2022
    Posts
    2
    Location

    How to login to SharePoint using VBA

    I am creating an access program that needs to access the Company SharePoint site. If the user has previously logged in using their Microsoft credentials, the code below maps an available drive letter to the SharePoint folder. However I would like to embed a specific user name and password in my code to access the SharePoint site. I was able to do this thru Internet Explorer, but Microsoft shut IE down on June 22nd and I’m not longer able to use the workaround.
    I’ve searched for 2 days and have not come up with any examples of code that allows me to login to SharePoint with a user name and password set in the code (Not necessarily the user name and password of the user). Any help would be greatly appreciated.

    Function fDownloadUpdaterFile(SharepointAddress As String, sLocalPath As String, sUpdateFileName As String) As Boolean
    Dim LocalAddress As String
        Dim sResult As String
        Dim sMappedDrive As String
    Dim objFolder As Object
        Dim objNet As Object
        Dim objFile As Object
        Dim fs As Object
    Dim bResult As Boolean
    'Create a mapped drive the the sharepoint folder
        sMappedDrive = fNextAvaliableDrive & ":"
        Debug.Print "Using mapped drive  " & sMappedDrive
    '20220616 - AMD Need these 3 lines to authenticate Sparepoint If they have authenticated from this computer in the past.
        Dim objFd As FileDialog
        Set objFd = Application.FileDialog(msoFileDialogFolderPicker)
        objFd.InitialFileName = "https://[Company Name].sharepoint.com"
    Set objNet = CreateObject("WScript.Network")
        Set fs = CreateObject("Scripting.FileSystemObject")
        Debug.Print "SP Folder to map to:" & SharepointAddress
        objNet.MapNetworkDrive sMappedDrive, SharepointAddress
    Set objFolder = fs.GetFolder(sMappedDrive)
    'Check if the file you want to download is there
        If Dir(sMappedDrive & "/" & sUpdateFileName) = "" Then
            fLog "Update Failed:  Could not find " & sUpdateFileName & " on sharepoint."
            fDownloadUpdaterFile = False
            GoTo fDownloadUpdaterFile_Exit
        End If
    'Download the file
        Debug.Print "Copying " & sMappedDrive & "/" & sUpdateFileName & " to " & fGetFrontEndPath & sUpdateFileName
        bResult = fCopyFile(sMappedDrive & "/" & sUpdateFileName, fGetFrontEndPath & sUpdateFileName)
    If bResult Then
            fDownloadUpdaterFile = True
        Else
            fDownloadUpdaterFile = False
        End If
    fDownloadUpdaterFile_Exit:
    On Error Resume Next
        objNet.RemoveNetworkDrive sMappedDrive, True, True
        Set objNet = Nothing
        Set fs = Nothing
        Exit Function
    fDownloadUpdaterFile_ERROR:
        If Err.Number = -2147023652 Then
            MsgBox "You need to relog into sharepoint."
        Else
            MsgBox Err.Number & ":" & Err.Description
            Debug.Print Err.Number & ":" & Err.Description
        End If
    fDownloadUpdaterFile = False
        GoTo fDownloadUpdaterFile_Exit
    End Function
    Last edited by Aussiebear; 06-27-2022 at 01:35 PM. Reason: Added code tags to supplied code

  2. #2
    VBAX Newbie
    Joined
    Jul 2019
    Posts
    1
    Location
    Were you able to get anywhere with this? I am having issues with sync'ing certain sharepoint folders so would find automated authentication useful for some applications as well.

  3. #3
    VBAX Newbie
    Joined
    Jun 2022
    Posts
    2
    Location

    Sharepoint VBA login.

    Quote Originally Posted by treflip View Post
    Were you able to get anywhere with this? I am having issues with sync'ing certain sharepoint folders so would find automated authentication useful for some applications as well.
    A little history. I wanted to use a company's sharepoint site to host the update files for a program I had written for them. So I was looking for a way for my program to login and check for an update. The isue was that some of the employees didn't have a sharepoint account. I also wasn't able to successfully loging with a generic account thru VBA. So I hired a company thru guru. They were able to create a workaround for me. Gave me code and instructions on how to install it on the (Update) folder sharepoint site. I then added vba code to my program that would authenticate to the folder. The installed software would then send (Download) the file you requested.

    So No I was not able to uathenticate as a user, but I was able to accomplish a work around.

    Adolph

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •