SOLVED

Update power query on startup

%3CLINGO-SUB%20id%3D%22lingo-sub-1819184%22%20slang%3D%22en-US%22%3EUpdate%20power%20query%20on%20startup%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1819184%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%202%20power%20query%20in%20an%20Excel%20workbook.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOnly%20one%20of%20the%20query%20refreshes%20on%20startup.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20set%20both%20query%20to%20Update%20on%20startup%2C%20by%20settings%20and%20with%20a%20vba%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20also%20use%20a%20vba%20code%20from%20access%20to%20open%20and%20Update%20the%20query.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20I%20refresh%20the%20query%20manually%20it%20works%20fine.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20anyone%20have%20experience%20with%20this%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1819184%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1819720%22%20slang%3D%22de-DE%22%3ESubject%3A%20Update%20power%20query%20on%20startup%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1819720%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F571539%22%20target%3D%22_blank%22%3E%40thansson%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3EThere%20are%20certainly%20others%20here%20who%20are%20much%2C%20much%2C%20much%20more%20familiar%20with%20PQ.%3CBR%20%2F%3EBut%20while%20reading%20your%20request%2C%20I%20did%20a%20little%20internet%20research%20and%20there%20was%20something%20...%20%3CBR%20%2F%3E%20attached%20is%20an%20additional%20VBA%20code%2C%20maybe%20it%20does%20what%20you%20imagined%2C%20should%20be%20a%20little%20food%20for%20thought.%20If%20not%2C%20please%20just%20ignore%20my%20post.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3EVBA%20Code%20freshly%20fished%20off%20the%20internet%2C%20for%20you%20%3CLI-EMOJI%20id%3D%22lia_slightly-smiling-face%22%20title%3D%22%3Aslightly_smiling_face%3A%22%3E%3C%2FLI-EMOJI%3E%3CBR%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%20class%3D%22text-wrap%20tlid-copy-target%22%3E%3CDIV%20class%3D%22result-shield-container%20tlid-copy-target%22%3E%3CSPAN%20class%3D%22tlid-translation%20translation%22%3E%3CSPAN%20class%3D%22%22%3EPublic%20Sub%20UpdatePowerQueries%20()%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3E'VBA%20to%20update%20data%20sources%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3EDim%20lngPowerQuery%20As%20Long%2C%20objDataSource%20As%20WorkbookConnection%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EDim%20objWorksheet%20As%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3EOn%20Error%20Resume%3CSPAN%3ENext%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EFor%20Each%20objDataSource%20In%20ThisWorkbook.Connections%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E'Workbook%20Query%20%3D%20Power%20Query%3F%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20lngPowerQuery%20%3D%20InStr%20(1%2C%20objDataSource.OLEDBConnection.Connection%2C%20%22Provider%20%3D%20Microsoft.Mashup.OleDb.1%22%2C%20vbTextCompare)%20%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20If%20Err.Number%20%26lt%3B%26gt%3B%200%20Then%20%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E%20Err.Clear%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EExit%20For%3C%2FSPAN%3E%3CBR%20%2F%3EEnd%3CSPAN%3EIf%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E'Power%20Query%3F%3C%2FSPAN%3E%20%3CSPAN%3EUpdate%20data%20source%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3E'Option%201%20-%20Update%20all%20data%20sources%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20lngPowerQuery%26gt%3B%200%20Then%20objDataSource.Refresh%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3E''%20Option%202%20-%20selectively%20update%20data%20sources%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3ESelect%20Case%20objDataSource.Name%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3ECase%20%22Query%20-%20List_Functions%22%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EobjDataSource.Refresh%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3ECase%20Else%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3EEnd%20Select%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3E'Output%20workbook%20query%20name%20in%20debugger%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3EDebug.Print%20objDataSource.Name%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22%22%3ENext%20objDataSource%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EEnd%20Sub%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22result-shield-container%20tlid-copy-target%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22result-shield-container%20tlid-copy-target%22%3E%3CP%3EHope%20I%20was%20able%20to%20help%20you.%3C%2FP%3E%3CP%3EI%20wish%20you%20continued%20success%20with%20Excel%20(the%20coolest%20invention%20since%20chocola...%20Uh...%20Microsoft!%20%3A-)))%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20be%20happy%20to%20know%20if%20I%20could%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22tlid-result-transliteration-container%20result-transliteration-container%20transliteration-container%22%3E%3CDIV%20class%3D%22tlid-transliteration-content%20transliteration-content%20full%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1844139%22%20slang%3D%22en-US%22%3EBetreff%3A%20Update%20power%20query%20on%20startup%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1844139%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20Nikolino%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETks.%20for%20your%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20already%20a%20VBA%20update%20data%20source%2C%20and%20after%20that%20I%20have%20a%20refresh.all.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20made%20it%20work%20with%20help%20of%20a%20delay.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20added%20a%20delay%20on%2010%20sec.%20between%20the%20update%20and%20the%20refresh%2C%20and%20this%20is%20working%2C%20Maybe%20not%3C%2FP%3E%3CP%3Ethe%20best%20solution%2C%20but%20it%20is%20working.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20your%20time%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1844304%22%20slang%3D%22de-DE%22%3ERE%3A%20Update%20power%20query%20on%20startup%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1844304%22%20slang%3D%22de-DE%22%3EYour%20Welcome%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hi

 

I have 2 power query in an Excel workbook.

 

Only one of the query refreshes on startup.

 

I have set both query to Update on startup, by settings and with a vba code.

 

I have also use a vba code from access to open and Update the query.

 

If I refresh the query manually it works fine.

 

Do anyone have experience with this?

3 Replies
Highlighted
Best Response confirmed by thansson (Occasional Contributor)
Solution

@thansson 

There are certainly others here who are much, much, much more familiar with PQ.
But while reading your request, I did a little internet research and there was something ...
attached is an additional VBA code, maybe it does what you imagined, should be a little food for thought. If not, please just ignore my post.

 

VBA Code freshly fished off the internet, for you

 

Public Sub UpdatePowerQueries ()
'VBA to update data sources
Dim lngPowerQuery As Long, objDataSource As WorkbookConnection
Dim objWorksheet As Worksheet

On Error Resume Next

For Each objDataSource In ThisWorkbook.Connections
'Workbook Query = Power Query?
lngPowerQuery = InStr (1, objDataSource.OLEDBConnection.Connection, "Provider = Microsoft.Mashup.OleDb.1", vbTextCompare)
If Err.Number <> 0 Then
Err.Clear
Exit For
End If
'Power Query? Update data source
'Option 1 - Update all data sources
If lngPowerQuery> 0 Then objDataSource.Refresh

'' Option 2 - selectively update data sources
Select Case objDataSource.Name
Case "Query - List_Functions"
objDataSource.Refresh
Case Else
End Select

'Output workbook query name in debugger
Debug.Print objDataSource.Name

Next objDataSource

End Sub
 

Hope I was able to help you.

I wish you continued success with Excel (the coolest invention since chocola... uh ... Microsoft! :-)))

 

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)

 
Highlighted

Hi Nikolino 

 

Tks. for your help.

 

I have already a VBA update data source, and after that I have a refresh.all.

 

I have made it work with help of a delay.

 

I added a delay on 10 sec. between the update and the refresh, and this is working, Maybe not

the best solution, but it is working.

 

Thank you for your time

Highlighted
Your Welcome