Hey all,
I have a bunch of excel workbooks that import via power query other exel workbooks and present it as clean data.
Now i need to open all these books and refresh the query as i keep dropping new data into it.
What i have now does not seem to do the trick....
I also tried RefreshAll when opening the files...
I have a bunch of excel workbooks that import via power query other exel workbooks and present it as clean data.
Now i need to open all these books and refresh the query as i keep dropping new data into it.
What i have now does not seem to do the trick....
I also tried RefreshAll when opening the files...
Code:
Public Sub refreshININ()
Dim fso As Object
Dim folder As Object
Dim file As Object
Dim con As WorkbookConnection
Dim Cnam As String
'the folder that contains the workbooks refresh
Path = "\\MyPath\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(Path)
With Application
.DisplayAlerts = False
.ScreenUpdating = False
.EnableEvents = False
.AskToUpdateLinks = False
End With
For Each file In folder.Files
If Right(file.Name, 4) = "xlsx" Or Right(file.Name, 3) = "xls" Then
Workbooks.Open Path & file.Name
For Each con In ActiveWorkbook.Connections
If Left(con.Name, 8) = "Query - " Then
Cname = con.Name
With ActiveWorkbook.Connections(Cname).OLEDBConnection
.BackgroundQuery = False
.Refresh
End With
ActiveWorkbook.Save
ActiveWorkbook.Close True
End If
Next con
End If
Next file
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.EnableEvents = True
.AskToUpdateLinks = True
End With
End Sub