Using vba code, how do I get the created date of an excel file saved in Sharepoint? Many Thanks.

Peter Charlton 10 Reputation points
2023-05-12T15:16:58.1666667+00:00

Hi, I've searched many solutions but none of them work. I'm basically just trying to get the creation date of an excel file saved on Sharepoint using VBA in Excel.

Microsoft 365 and Office SharePoint Server For business
Microsoft 365 and Office Excel For business Windows
{count} votes

1 answer

Sort by: Most helpful
  1. Tanay Prasad 2,250 Reputation points
    2023-05-15T06:22:00.4966667+00:00

    Hi,

    To get or retrieve the created date of an Excel file saved in SharePoint using VBA, you can use the SharePoint Object Model.

    Here's an example code snippet-

    Sub GetSharePointFileCreatedDate()
        Dim siteUrl As String
        Dim fileUrl As String
        Dim spSite As Object
        Dim spWeb As Object
        Dim spFile As Object
        
        ' Set the SharePoint site URL
        siteUrl = "https://your-sharepoint-site-url"
        
        ' Set the file URL (relative to the SharePoint site)
        fileUrl = "/sites/your-site/library/your-excel-file.xlsx"
        
        ' Create SharePoint site and web objects
        Set spSite = CreateObject("SPSite")
        Set spWeb = spSite.OpenWeb(siteUrl)
        
        ' Get the file from SharePoint
        Set spFile = spWeb.GetFile(fileUrl)
        
        ' Display the created date of the file
        MsgBox "Created Date: " & spFile.TimeCreated
        
        ' Clean up objects
        Set spFile = Nothing
        spWeb.Close
        spSite.Close
    End Sub
    
    

    Make sure to replace the siteUrl and fileUrl variables with the actual SharePoint site URL and the relative file URL within the site. When you run the GetSharePointFileCreatedDate subroutine, it will retrieve the created date of the specified Excel file saved in SharePoint and display it in a message box.

    Best Regards.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.