简体   繁体   中英

VB.NET Enable AutoFilter in protected Excel

I'm trying to enable the filter option when protecting the worksheet but I couldn't able to.

         If Trial Then
             'add filter on header
             oSheet.Range("A2").AutoFilter()
             oSheet.EnableAutoFilter = True
             oSheet.Range("A1:A1").Style.Locked = True
             oSheet.Protect("SamplePassword")
         Else
             oSheet.Range("A1:" & colAlpha & count).AutoFilter()
         End If

This is the option I want to enable - which allow the user to filter even the Excel is protected.

在此处输入图像描述

As you can see, I tried to apply [EnableAutoFilter] in my code but it does not work. Below is my sample result

在此处输入图像描述

The filter has applied, but I couldn't select to filter - only default to all. Please let me know if you have done something similar before, I've been trying to google all day long and still no luck. Much appreciate!

I've done some additional research and found out there is a method applicable to the above question

Worksheet.Protect method

As here mentioned, instead of just applying Protect("Password"), you can define different types of parameters, as below:

oSheet.Protect("SamplePassword", False, True, True, True, False, False, False, False, False, False, False, False, False, True, False)

and refer to the documentation for reference to turn on / off on "Setting"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM