Powershell using Excel.Application

Jay 21 Reputation points
2023-02-23T19:53:19.4533333+00:00

I have a PS script that uses Excel.Application to open an excel file, refresh external data, recalculate formulas and then save the file. This works perfectly.
However if I map a network drive to a SharePoint document library it does everything except save the file.
When I do this outside of SharePoint there is no prompt to save (good)
If I do this with a xlsx file in SharePoint there is a prompt asking me if I want to over right the file, I click yes but the file is not updated.
The file is not locked. It is not lacking mandatory metadata, I have all the permissions required, I know that the work is being done but not the save.
Any idea why SharePoint would be blocking the save even when it prompts me to confirm?

Excel
Excel
A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
2,175 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,868 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 39,761 Reputation points Microsoft External Staff
    2023-02-24T05:58:09.1633333+00:00

    Hi @Jay,

    You can use display alerts statement before SaveAs

    $excel.DisplayAlerts = $false;
    $excel.ActiveWorkbook.SaveAs($xlsFile);
    
    

    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.