none
Protect Power Query using VBA RRS feed

  • Question

  • Hi,

    By using "Protect Workbook", I can grey out queries in Power Query, protecting them from editing. However, the queries will not be able to refresh at the same time.

    I thought there was a way by using below code.

    Sub Refresh()

    ActiveWorkbook.Protect Password:="password", Structure:=False, Windows:=False 'Unprotect

    For Each cn In ThisWorkbook.Connections
    If cn = "QueryName" Then
        With cn
            .OLEDBConnection.BackgroundQuery = False
            .Refresh
            .OLEDBConnection.BackgroundQuery = True
        End With
    End If
    Next cn

    ActiveWorkbook.Protect Password:="password", Structure:=True, Windows:=True 'Protect

    End Sub

    But, the workbook will be locked again before query downloading is finished, causing downloading failed, like below.

    Is there any way that we can use to postpone "locking" workbook?

    Thanks

    

    Tuesday, October 18, 2016 8:20 PM

Answers

All replies