I need help with some code, i am using power query on a worksheet that is protected and the workbook is protected as well, i am traying to write a code that will refresh the power query for new information and i have this:
Private Sub CommandButton2_Click()
ActiveWorkbook.Unprotect Password:="Aerogroup"
Sheets("4").Unprotect Password:="abc"
Range("A2").Select
ActiveWorkbook.RefreshAll
ActiveWorkbook.Protect Password:="Aerogroup"
Sheets("4").Protect Password:="abc"
End Sub
this dirent work because it say that the workbook is protected and cant refresh the power query table, so i did this:
Private Sub CommandButton2_Click()
ActiveWorkbook.Unprotect Password:="Aerogroup"
Sheets("4").Unprotect Password:="abc"
Range("A2").Select
ActiveWorkbook.RefreshAll
If Application.Wait(Now + TimeValue("0:00:10")) Then
MsgBox "Actualizado"
End If
ActiveWorkbook.Protect Password:="Aerogroup"
Sheets("4").Protect Password:="abc"
End Sub
this also did not work, it run the 10 sec showed the msgbox and then again the "cant refresh this workbook is protected".
anyone has a solution to this please?
Bookmarks