Sub UpdateQueriesInOrder()
Dim wb As Workbook
Dim conn As WorkbookConnection
Set wb = ThisWorkbook
Application.ScreenUpdating = False
On Error GoTo ErrorHandler
' 1段階目: qyファイルへの接続を更新
For Each conn In wb.Connections
If conn.Name = "接続名1" Then ' SPOリスト取得のクエリ名
conn.OLEDBConnection.BackgroundQuery = False
conn.Refresh
Exit For
End If
Next conn
' 2段階目: Power Queryの加工クエリを更新
For Each conn In wb.Connections
If conn.Name = "接続名2" Then ' 加工クエリ名
conn.OLEDBConnection.BackgroundQuery = False
conn.Refresh
Exit For
End If
Next conn
Application.ScreenUpdating = True
MsgBox "データの更新が完了しました", vbInformation
Exit Sub
ErrorHandler:
Application.ScreenUpdating = True
MsgBox "エラーが発生しました: " & Err.Description, vbCritical
End Sub
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme