Update an existing named item in Microsoft Excel

Tintin10 40 Reputation points
2025-11-07T15:56:20.2166667+00:00

Hello. I currently develop an application that targets to write into Microsoft Excel files on Sharepoint drives.

To perform this action, I use Microsoft Graph 5.91.

The application uses .NET Framework 4.8 in C#.

During the process, I have to create, modify or delete named ranges. If the creation and the deletion work fine, this is not the case of the update, which I wrote as follows :

public async void UpdateNamedRange(string excel365FileId, string rangeName, string rangeA1)

{

WorkbookRequestBuilder workbookRequestBuilder = driveRequestBuilder.Items[excel365FileId].Workbook; ``//driveRequestBuilder is of type Microsoft.Graph.Drives.Item.DriveItemRequestBuilder

WorkbookNamedItem body = new WorkbookNamedItem()

{

Value = new UntypedString(rangeA1)

};

_ = await workbookRequestBuilder.Names[rangeName].PatchAsync(body);

}

I’m forced to delete and add the named range, which is odd.

What’s going wrong in here ? Is this a bug in Microsoft Graph, as there seem to have quite a bit ?

Thanks in advance.

Microsoft 365 and Office | Development | Other
0 comments No comments
{count} votes

Answer accepted by question author
  1. Austin-H 6,990 Reputation points Microsoft External Staff Moderator
    2025-11-08T01:15:01.96+00:00

    Hello Augustin Chevrier
    Thank you for posting question to Microsoft Q&A Forum.
    According to this issue, I've conducted a research about this, mainly on these two articles:
    https://learn.microsoft.com/en-us/graph/api/range-update?view=graph-rest-beta&tabs=javascript
    https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2499
    From my perspective view after checking this, and your code - the explanation should be:
    PatchAsync on Workbook.Names[rangeName] calls the named item PATCH endpoint, which only supports updating metadata (like comment or visible) and, for constant names, the value (formula).

    It does not update the RefersTo property (the A1 reference for range-type names). The API does not expose a way to change the address of a named range via PATCH.

    So:

    • PatchAsync(body) works for visibility or comment changes.
    • It fails for retargeting a named range because that property isn’t supported.

    That's why your finding for this solution would result in deleting and add the name range. I could not find any official Microsoft Graph documentation that supports updating a named range’s reference (where it points) using PATCH. The API only allows updating metadata via PATCH, and the recommended approach for changing the reference is to delete the named item and add it again with the new address.
    You might need to submit a feedback to Microsoft Graph section in Feedback portal: https://feedbackportal.microsoft.com/feedback/forum/ebe2edae-97d1-ec11-a7b5-0022481f3c80
    As this feedback gains more votes, this should bring attention to back-end team to improve it in future Microsoft Graph update.
    I hope this information is helpful. Please let me know if you have any further questions.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".      

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. 


0 additional answers

Sort by: Most helpful

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.