Protect workbook

A

Alex

I'm trying two things that aren't working and it's driving me nuts. I need
my workbook protected when the workbook is opened. For some reason, workbook
protection is a toggle. I'll open it once and it's protected. I'll open it
next time and it's not protected. The other thing I can't get to work is to
turn on autofilter in sheet 'ImportData' each time the workbook opens. Any
ideas what I'm doing wrong? I've tried for hours. . . thanks.

Here's my code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveSheet.AutoFilterMode = False
End Sub

Private Sub Workbook_Open()

On Error Resume Next
AddIns("Analysis ToolPak").Installed = True
AddIns("Analysis ToolPak - VBA").Installed = True

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect password:="mwimport"
Next ws

Worksheets("ImportData").Range("A1:p5000").Locked = True
Worksheets("Trends").Range("A1:BC25").Locked = True
Worksheets("Chart Data").Range("A1:W72").Locked = True

Dim wsh As Worksheet
For Each wsh In ThisWorkbook.Worksheets
wsh.Protect password:="mwimport"
Next wsh

'Hide the OriginalTrends sheet
Sheets("OriginalTrends").Visible = False

Worksheets("ImportData").Unprotect password:="mwimport"
Worksheets("ImportData").Activate
Range("A1").Select
ActiveSheet.AutoFilterMode = True
ActiveWorkbook.Protect password:="mwimport"

End Sub
 
D

dan dungan

I need my workbook protected when the workbook is opened.

It's protected when I open it.
The other thing I can't get to work is to turn on autofilter in sheet >'ImportData' each time the workbook opens.

From excel 2000 vba help

AutoFilterMode Property


True if the AutoFilter drop-down arrows are currently displayed on the
sheet. This property is independent of the FilterMode property. Read/
write Boolean.

Remarks

This property returns True if the drop-down arrows are currently
displayed. You can set this property to False to remove the arrows,
but you cannot set it to True. Use the AutoFilter method to filter a
list and display the drop-down arrows.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top