Overview
- My SQL Query and Related Office Script I am getting acquainted with Office Scripts and the ability to trigger those scripts via PowerAutomate flows.
- My Use Case I want to schedule a nightly refresh of a SQL query housed within my Excel workbook. I currently refresh it manually via a PowerShell script, which isn't ideal.
- Successful SQL Query Refresh Via Office Script I have created an Office Script within my Excel workbook which is configured to refresh that SQL query. I use the RefreshAllDataConnections() method to accomplish this refresh. It works perfectly; I run the script, triggering the query, and my workbook updates accordingly! Now I just need to automate that triggering of that script. Please see below.
- Triggering the Office Script via PowerAutomate I have configured a PowerAutomate flow to trigger the above Office Query. All tests of this PowerAutomate flow come back "successful".
Issue
- Workbook Not Saving The successfully refreshed Excel workbook is not saved after the query runs, which negates the purpose of the PowerAutomate flow. (Note: This is how I've interpreted the issue. It's possible that I am diagnosing it incorrectly!)
- Illustration Let's say that my query was run on 4/12 and the "Date Last Run" column therefore currently shows "4/12". When I run the PowerAutomate (and trigger the Office Script) on 4/13, and then open the Excel workbook to review the results, the "Date Last Run" column still shows "4/12", whereas I expected "4/13".
Question
Is there some way that I can configure my Office Script to save my Excel workbook after the RefreshAllDataConnections() fires?