Automatically refresh SharePoint stored Excel Power Query Table when the workbook is closed

Anonymní
2024-08-21T06:23:13+00:00

Hi everyone,

I’ve been struggling with automatically refreshing my Power Query Table in an Excel Workbook. I’ve already tried the following, but nothing seems to work:

  1. Creating a Power Automate flow that runs a script intended to refresh all queries. The script works well when triggered manually, but the flow doesn’t, even though it was created correctly.
  2. Using a VBA code scheduled to automatically refresh the data. Again, it works fine when run manually (see the code below).
  3. Using the Task Scheduler to open the Workbook daily at 8 am. Unfortunately, this also didn’t work.

I think I’ve run out of options. Could the issue be because the file is stored on SharePoint?

The challenge I’m facing is that I receive multiple Excel files every week via email, with the data stored as ranges. I’ve created a flow that saves these files to a designated location and then deletes the emails.

Afterward, I need to merge and update the downloaded data in my master Excel sheet, which I’ve been doing using Power Query. From this master sheet, I have more than 20 other Excel workbooks created (also connected to the master sheet via Power Query), each tailored to individual employees. These workbooks only include the rows where the employees’ names appear, as I need to share the updated data with them separately.

Do you have any other ideas on how to achieve this? Perhaps even without using Power Query? I’m open to trying anything.

Thank you so much!

P.S.: The VBA code goes as follows:
Public ReloadInterval As Double

Public Const Period = 30

Sub Reload()

MsgBox "Updates will begin to occur at " & _

"the interval of " & Period & " seconds" 

Call FirstReload

End Sub

Sub FirstReload()

ReloadInterval = Now + TimeSerial(0, 0, Period)

Application.OnTime _

EarliestTime:=ReloadInterval, \_ 

Procedure:="ReloadConnections", \_ 

Schedule:=True 

End Sub

Sub ReloadConnections()

ThisWorkbook.RefreshAll

Call FirstReload

End Sub

Microsoft 365 a Office | Instalovat, uplatnit, aktivovat | Jiné | Jiné

Otázka je uzamčená. Tato otázka se migrovala z komunity podpory Microsoftu. Můžete hlasovat, jestli je užitečná, ale nemůžete k ní přidávat komentáře či odpovědi ani ji nemůžete sledovat.

Počet komentářů: 0 Žádné komentáře

Odpovědi: 6

Seřadit podle: Nejnovější
  1. Miroslav Pragl 78,861 Reputační body Dobrovolný moderátor
    2024-08-23T12:08:58+00:00

    Kde je to running? Ty to spoustis neinteraktivne?

    jak jsem psal, nejsprve spust interaktivne primo ze svych windows s ObjExcel.Visible = True

    pote pod tim samym uzivatelem trebars z task scheuleru. POZOR, pravdepodovne nebudou k dispozici mapovane sitove disky atd atd!

    MP

    Byla tato odpověď užitečná?

    Počet komentářů: 0 Žádné komentáře
  2. Anonymní
    2024-08-23T11:40:48+00:00

    Ahoj, skúsila som, žiaľ, všetko vyzerá byť ok, len mi to stále ukazuje ako Running - aj po 24 hodinách, odkedy to bolo spustené. Ďakujem ti ale každopádne za pomoc!

    Byla tato odpověď užitečná?

    Počet komentářů: 0 Žádné komentáře
  3. Miroslav Pragl 78,861 Reputační body Dobrovolný moderátor
    2024-08-21T17:34:46+00:00

    Podle toho, kolik milionu radku ze zpracovava. Takze 1 minuta .. 1 hodina

    Zkus nejprve s ObjExcel.Visible = True (zda excel nevypise nejakou chybu). Take kontroluj v task manageru, zda Excel bezi a konzumuje CPU

    MP

    Byla tato odpověď užitečná?

    Počet komentářů: 0 Žádné komentáře
  4. Anonymní
    2024-08-21T15:00:29+00:00

    Ďakujem za tip! Ako dlho u teba, prosím, trvá samotný refresh. Mne už ten task beží viac ako 40 minút a zatiaľ sa nič nedeje...

    Byla tato odpověď užitečná?

    Počet komentářů: 0 Žádné komentáře
  5. Miroslav Pragl 78,861 Reputační body Dobrovolný moderátor
    2024-08-21T13:03:44+00:00

    Nestacil by nocni refresh? Ja pouzivam letity VBScript v taskscheduleru:

    Function RefreshPowerPivot(XLPath) 
    
        Set ObjExcel = CreateObject("Excel.Application") 
    
        ObjExcel.Visible = False 
    
        Set objWorkBook = ObjExcel.Workbooks.Open(XLPath) 
    
        objWorkBook.Model.Refresh 
    
        objWorkBook.Save 
    
        objWorkBook.Close 
    
        ObjExcel.Quit 
    
        Set objWorkBook = Nothing 
    
        Set ObjExcel = Nothing 
    
    End Function
    

    samozrejme si pripoji Sharepoint jako sitovy disk

    MP

    Byla tato odpověď užitečná?

    Počet komentářů: 0 Žádné komentáře