Dynamics 365 Business Central: How to disable “Edit in Excel” on a specific page

Dynamics 365 Business Central

Hi, Readers.
With pages in Business Central that display a list of records in rows and columns, like a list of items, sale orders, or invoices, you can export the list to Microsoft Excel, and view it there. Depending on the page, you have two options for viewing in Excel. Both options are available from the Share icon Share a page in another app. at the top of a page. You can either select the Open in Excel action or the Edit in Excel action on the page.

We also discussed How to add Edit in Excel to Card and Document Pages two months ago.

As you might know, we can use standard Permission Sets to manage Edit in Excel permissions for users.

Recently I saw an interesting question, is there any way to disable the Edit in Excel for a specific page?

In my other past post, How to add new button (action) to Share group (In Share Icon), we can know that the keyword of Edit in Excel action may be ‘EditInExcel’.

But when we use Pageextension to modify it, it will prompt that the action is not found.

So should we give up? No!!!! Let’s go on.

We can find the only IntegrationEvent, OnEditInExcel() event in codeunit 1481 “Edit in Excel”.

So we can subscribe this event in our codeunit.

This time we can use the Service Name to target a specific page.
Service Name: The name of the web service already created for use with Edit in Excel.

For example:

Let’s take Item List page as an example.
The service name is ‘Item_Card_Excel‘.

I’m sure you already know the next.😁

Test video: This does not affect other pages and the Open in Excel feature.

Test code:

codeunit 50111 MyCodeunit
    [EventSubscriber(ObjectType::Codeunit, Codeunit::"Edit in Excel", 'OnEditInExcel', '', false, false)]
    local procedure OnEditInExcel(ServiceName: Text[240]; ODataFilter: Text; SearchFilter: Text; var Handled: Boolean);
        if ServiceName = 'Item_Card_Excel' then
            Error('You can not use Edit in Excel on the Item List page!!!');

Isn’t it simple. Give it a try!!!😀

PS: You can use the method I tested to get the Service Name of the page. In fact, the Service Name is automatically generated in codeunit 1482 “Edit in Excel Impl.”, if you don’t like this hard coding, you can refer to the standard code to generate the same Service Name.


Hope this will help.

Thanks for reading.



Copied title and URL