cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Regular Visitor

data connection refresh excel with flow

Hello,

 

I have an excel workbook saved in a document library on sharepoint. The excel file contains a table with data from a .txt file.

 

every day a new .txt file is emailed, and I have used flow to save the file in sharpoint.

 

I have the data connection set to refresh in the background, and refresh on opening.

 

so every day I open excel, allow the table to refresh, save and close.

 

i'd really like to have flow do this data refresh without opening excel... is this possible?

7 REPLIES 7
Super User II
Super User II

mmm using defaut PA actions not, but you can use UI flows to make this open excel proces automated.



Did I answer your question? Please consider to Mark
my post as a solution! to guide others :winking_face:

Proud to be a Flownaut!


If you want you can follow me at www.christianabata.com Quieres contenido en español? Síguenos en Power Automate LA

how do i use flow to open and refresh the data connection on the excel file?

 

I already have the data source (txt file) saving daily automatically

 

now i need to refresh the excel file daily and save.

 

that way when it saves i can have flow email it. is this possible?

no my friend by using PA you can't open a file. Just with UI 



Did I answer your question? Please consider to Mark
my post as a solution! to guide others :winking_face:

Proud to be a Flownaut!


If you want you can follow me at www.christianabata.com Quieres contenido en español? Síguenos en Power Automate LA

is it possible to refresh the data without opening the file? I would prefer to not set up a ui flow so it can still run if im not logged into my computer.

 

i tried this but it doesnt work

 

when a file is created or modified in a folder (this is where the text file is)

list rows present in a table (this is in the excel file)

apply to each> update a row 

 

4-22-2020 4-58-44 PM.jpg

 

 

 

Regular Visitor

1) Save the excel xlsx file to one drive or SharePoint and make sure you do not keep a local copy that is syncing. If you are keeping a local copy of the report it will prevent the refresh because it causes a lock: see step 4: https://support.microsoft.com/en-us/office/excel-file-is-locked-for-editing-6fa93887-2c2c-45f0-abcc-...

 

2) in excel online, open the xlsx file recommend going to file\info and protect the sheet. This set the sheet to view mode when opening, as an added precaution.

 

3) in excel online (this only works in online and the file has to be an xlsx and not a xlsm file), click on "Automate" and "code editor."

 

4) put this code in:

 

function main(workbook: ExcelScript.Workbook) {

// Refresh all data connections

let selectedSheet = workbook.getActiveWorksheet();

selectedSheet.refreshAllPivotTables();

}

 

5) make sure you checkmark the "share with others in the workbook" in the script so power automate can see the script.

 

6) in power automate, do the excel online (business), trigger script connector. Select your script and done!

New Member

Hi @paulburnett224 . Couple questions for you. If you have two connection queries, will your code above refresh both queries ? The data from each query is located on its own spreadsheet within the workbook. I added the code using the automate tab and i also allowed the code to be shared so that it's picked up by my flow. Please see my flow attached. When my flow sends me the attached report, the queries within the report still have not been updated. Can you let me know any issues you see or any watch outs i should be concerned with as i'm trying to figure out why it's not refreshing ?

 ThanksMy Flow.png

A few points: 

The documentation on running a script in excel from power automate is here:

https://docs.microsoft.com/en-us/connectors/excelonlinebusiness/#run-script-(preview)

You'll be using an action, not a trigger.

The sample code you provided is to refresh a pivot table  (selectedSheet.refreshAllPivotTables();)

This solution did not work for me, as my data connection is to a source that requires authentication to perform the refresh.

 

Helpful resources

Announcements
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Users online (2,942)