Macros - Filters

  • Thread starter Thread starter Pinda
  • Start date Start date
P

Pinda

I have this bit of code that I recorded as a macro,edited
it slightly and then assigned it to a button:-

Sub AleBak()
'
' AleBak Macro
' Macro recorded 30/09/2003 by Bhupinder Rayat
'

'
Sheets("LDP Template").Select
ActiveSheet.AutoFilterMode = False
Range("A7").AutoFilter Field:=7, Criteria1:="Alex
Baker"
End Sub


The code works fine, but falls down when I password
protect the worksheets. It has a problem with the line...

ActiveSheet.AutoFilterMode = False

The error message is, 'Unable to set the AutoFilter mode
property of the worksheet class.'

Can anyone tell me why this is?

Thanks in advance.

Pinda.
 
You need to set the EnableAutoFilter property to True and protect
using userInterfaceOnly:

With Sheets("LDP Templates")
.EnableAutoFilter = True
.Protect Password:="pword", _
contents:=True, _
userInterfaceOnly:=True
End With

Unfortunately, those properties need to be set on a per session
basis, so you'll probably want to include them in a Workbook_Open
event macro (stored in the ThisWorkbook code module)
 
Back
Top