TheMadTree
New Member
- Joined
- Mar 23, 2015
- Messages
- 25
Good afternoon All,
My first post to MrExcel B)
I want a macro that password protects all sheets in the workbook called 'Potato' when the workbook is closed.
For some reason it doesn't work and I can't figure our why :s
Can anyone help me?
This is what I've written:
Option Explicit
Sub Protectsheets_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
Dim pwd As String
pwd = Orange30
For Each ws In Workbooks("Potato.xlsm").Worksheets
ws.Protect Password:=pwd, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True
Next ws
If Me.Saved = False Then Cancel = True
End Sub
My first post to MrExcel B)
I want a macro that password protects all sheets in the workbook called 'Potato' when the workbook is closed.
For some reason it doesn't work and I can't figure our why :s
Can anyone help me?
This is what I've written:
Option Explicit
Sub Protectsheets_BeforeClose(Cancel As Boolean)
Dim ws As Worksheet
Dim pwd As String
pwd = Orange30
For Each ws In Workbooks("Potato.xlsm").Worksheets
ws.Protect Password:=pwd, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowSorting:=True
Next ws
If Me.Saved = False Then Cancel = True
End Sub