0

I am working on a report which consists of ActiveX plugins and the data is supposed to filter based on change in the selection. All works well, but I am getting the "RUNTIME ERROR 91" every time I open the file with different filename.

I need to share these password-protected files to more than 10 clients at once and don't want them to get these errors.

My code:

Sub advancedfilter_protect()

    'Disable Screen Updating
    Application.ScreenUpdating = False

    Dim actvsht As Worksheet
    
    Set actvsht = ActiveWorkbook.ActiveSheet

        For Each actvsht In ActiveWorkbook.Worksheets
        actvsht.Activate
        actvsht.Unprotect "Password"
        Next
    
            Call advancedfilter_data
    
        For Each actvsht In ActiveWorkbook.Worksheets
            actvsht.Protect "Password", UserInterfaceOnly:=True
        Next

End Sub

enter image description here

ZygD
  • 22,092
  • 39
  • 79
  • 102
  • 2
    Remove the `Set actvsht = ActiveWorkbook.ActiveSheet`. – BigBen Mar 12 '21 at 14:09
  • You may also want to read [How to avoid using Select](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). Its suggestions also apply to avoiding using `Activate` and `ActiveSheet` and so on. – BigBen Mar 12 '21 at 14:16
  • And that made it look so easy. Code works well now. Thanks – Chandan Pathak Mar 14 '21 at 10:02

0 Answers0