Stop Excel files from being opened in browser

Adam Baker 0 Reputation points
2025-06-16T16:21:20.98+00:00

I need to run a macro on excel opening to find the username to display only required data. This wont work if the file is opened in a browser.

a. Is there anyway of completely stopping a file from being opened in a browser?

b. If not, is there anyway of finding a username from someone opening an excel file in a browser and stopping data being displayed until this can be used?

Thanks

Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,936 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dora-T 1,085 Reputation points Microsoft External Staff Moderator
    2025-06-17T03:56:40.5266667+00:00

    Hi @Adam Baker

    Thanks so much for reaching out to the Microsoft Q&A Forum. 

    I understand you’re using a macro to check the username when the file opens and display only the required data, but that approach isn’t working when the file is opened in a browser.  

    Unfortunately, Excel Online doesn’t support VBA, so there’s currently no built-in way to detect the username or run any macros when the file is opened in the browser. Macros only work when the file is opened in the desktop version of Excel, so any logic based on user identity would need to happen there. 

    Based on what I’ve researched, there’s a setting you can try if your Excel file is stored in a SharePoint Online document library, it may help encourage the file to open in the desktop app: 

    • Go to the document library. 
    • Click the gear icon > Library settings. 
    • Select Advanced settings. 
    • Under “Opening Documents in the Browser”, choose “Open in the client application”. 
    • Save your changes. 

    User's image

    In addition, I also tried changing the setting in Excel itself by going to: 

    • Go to Excel > File > Options. 
    •  Advanced  
    • Open Word, Excel, and PowerPoint files using: Desktop app

    User's image

    I gave it a try myself, but unfortunately it hasn’t worked just yet, it’s possible the change needs a bit of time to take effect. I’ll monitor it and keep you posted if anything changes. 

    Feel free to give it a try on your end and let me know how it goes.


    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.


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.