Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default Protect workbook when saving

Hi,

I have a macro below that needs recoded as it's not working, I am looking
for the macro so when I press the save button it automatically protects all
the worksheets in the workbook.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ProtectAllSheets.protect Password:="ABCD"
End With
Application.EnableEvents = False
ThisWorkbook.Save
Application.EnableEvents = True
End Sub


Many thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Protect workbook when saving

hi
perhaps you are looking for the before save event not the before close event.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

regards
FSt1

"santaviga" wrote:

Hi,

I have a macro below that needs recoded as it's not working, I am looking
for the macro so when I press the save button it automatically protects all
the worksheets in the workbook.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ProtectAllSheets.protect Password:="ABCD"
End With
Application.EnableEvents = False
ThisWorkbook.Save
Application.EnableEvents = True
End Sub


Many thanks

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 178
Default Protect workbook when saving

Hi, i've replaced with the new line of code but still not functioning I think
rest of code might be wrong any ideas?

Regards

"FSt1" wrote:

hi
perhaps you are looking for the before save event not the before close event.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

regards
FSt1

"santaviga" wrote:

Hi,

I have a macro below that needs recoded as it's not working, I am looking
for the macro so when I press the save button it automatically protects all
the worksheets in the workbook.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ProtectAllSheets.protect Password:="ABCD"
End With
Application.EnableEvents = False
ThisWorkbook.Save
Application.EnableEvents = True
End Sub


Many thanks

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Protect workbook when saving

Try the following code in the ThisWorkbook module:

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
WS.Protect ' password:="your password"
Next WS
End Sub


--
Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2008
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)

"santaviga" wrote in message
...
Hi,

I have a macro below that needs recoded as it's not working, I am looking
for the macro so when I press the save button it automatically protects
all
the worksheets in the workbook.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ProtectAllSheets.protect Password:="ABCD"
End With
Application.EnableEvents = False
ThisWorkbook.Save
Application.EnableEvents = True
End Sub


Many thanks


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can protect worksheet then workbook but not Protect and Share in code [email protected] Excel Programming 7 January 16th 17 07:01 AM
Protect Workbook Vs Protect Sheet Poor_pakistani New Users to Excel 4 May 25th 06 02:06 PM
Disable Tools, Protect, Protect Workbook Paul Moles Excel Programming 1 September 5th 05 03:37 PM
Running a macro to protect a workbook on a already protected workbook UNprotects the workbook ?? WimR Excel Programming 9 July 25th 05 12:44 PM
Saving a Workbook: Forcing User to Rename before Saving Rollin_Again[_6_] Excel Programming 5 April 16th 04 02:54 PM


All times are GMT +1. The time now is 05:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"