0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

データ更新VBA

Posted at
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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?