I have been trying to automatically refresh my table (obtained from an SQL database via power query) and directly save it as a text file (tab delimited) I'm very new with VBA and the macro i used is
Public Sub UpdatePowerQueries()
'Macro to update the Power Query script(s) and save the file as .txt
Dim cn As WorkbookConnection
For Each cn In ThisWorkbook.Connections
If Left(cn, 13) = "Power Query -" Then cn.Refresh
Next cn
Application.DisplayAlerts = False
ActiveSheet.SaveAs Filename:="customfile" & Format(Date, "yyyymmdd") & ".txt", FileFormat:=xlTextWindows
Application.DisplayAlerts = True
End Sub
now the issue I've been facing is that the refresh part and the save part work ok on their own, but if I put them in the same macro, the save part happens too soon, and the text file is empty. Can anyone help me ?
Thanks