How to save a worksheet as pdf into a SharePoint list and include the metadata at the same time

Maria Z 20 Reputation points
2025-06-04T05:03:42.1233333+00:00

I have written vba that saves the current worksheet in excel as a pdf to a SharePoint document list. I would like to save the metadata for the list at the same time. The metadata exists in named cells in the excel worksheet.

This is the vb code I am using to save the pdf of the worksheet to SharePoint. I just want to include the metadata properties too.

'Create the PDF and save into the SharePoint List

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _

    FileName:=MySharePointPath & MyFileName, _

    Quality:=xlQualityStandard, _

    IncludeDocProperties:=True, _

    IgnorePrintAreas:=False, _

    OpenAfterPublish:=False
Developer technologies | VB
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Adiba Khan 1,440 Reputation points Microsoft External Staff
    2025-11-13T12:43:17.21+00:00

    Thank you for reaching out and sharing the details of your scenario. I understand that you are currently exporting an excel worksheet as a PDF to a SharePoint document library using VBA, and you would also like to automatically save metadata to the corresponding SharePoint list item at the same time.

    While excel’s ExportAsFixedFormat method supports exporting the file to SharePoint paths, it does not automatically attach or sync matter data to the documents associated SharePoint columns. To achieve this you will need to combine 2 operations:

    1.      save the worksheet as a PDF file to SharePoint.

    2.      Update the metadata fields for that file using SharePoint APIs(via Microsoft graph, rest API, auto power automate)

    Option 1: VBA solution using SharePoint rest API

    you can extend your VBA code to make a rest API call to SharePoint after saving the file.

    Option 2: use power automate for metadata update(recommended)

    I asked him blood and more reliable method is to use power automate(flow):

    1.      continue using your VBM macro to export and save the PDF to your SharePoint document library

    2.      create a power automate flow that triggers “when a file is created or modified in a document library”

    3.       In the flow, use “get file metadata” and " Update the file properties" actions to:

    ·         Read metadata values(you can have VBA write them into a hidden excel file, JSON file or naming convention).

    ·         Update the SharePoint file’s metadata columns accordingly.

    This approach avoids rest authentication issues and uses Microsoft supported no code automation tools.

    Option 3: using Microsoft graph API(advanced)

    If you have registered an Azure AD app, you can programmatically,

    ·         Upload the pdf using Graph Files API (/sites/{siteid}/drive/items/{itemID}/content)

    ·         Upload the associated ListItem fields using /sites/{siteId}/lists/{listId}/Items/{ItemsId}/fields.

    References:

    Working with files in Microsoft Graph - Microsoft Graph v1.0 | Microsoft Learn

    Update listItem - Microsoft Graph v1.0 | Microsoft Learn

    Please let us know if you require any further assistance we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer".


Your answer

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