Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default protecting the workbook through a macro

Ok, starting tommorow, another department has to see my workbook. Now,
would just share the workbook through the network, but since pages ar
added to the workbook as it's updated, i can't have that feature
Instead, i'll just do a savecopyas within my macro that i use to updat
the workbook. The thing is, i don't want them to be able to alter an
data in any cell of the workbook(they don't know vba, so i'm no
worried about them trying to alter code), further more, i don't wan
them to be able to save the workbook (which i already have the code fo
below), so is there someway to say in vba "if the workbook isn't i
drive I:\ (no matter where it is in drive I:\, as long as it's there
then make it so that every cell in this workbook is protecte
(password=no2cs), and the workbook is unsavable" ...that code wouldn'
go in the macro code, would it?

code for making the workbook unsavable as someone has given me:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
End Sub

thanks in advance for your help :

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default protecting the workbook through a macro

If the user opens the workbook with macros enabled, then you could use this kind
of code (also under ThisWorkbook):

Option Explicit
Private Sub Workbook_Open()

Dim wks As Worksheet

If LCase(Left(ThisWorkbook.Path, 1)) = "i" Then
'do nothing
Else
For Each wks In ThisWorkbook.Worksheets
With wks
.Activate
.Unprotect Password:="no2cs"
.Cells.Locked = True
.Protect Password:="no2cs"
End With
Next wks
End If

End Sub

But it might be better saving the file with all the cells locked. Then
unprotect the worksheets, unlock the cells that should be unlocked, then
reprotect the sheet--if the file is on the i: drive.



But it may be bet

"abxy <" wrote:

Ok, starting tommorow, another department has to see my workbook. Now, i
would just share the workbook through the network, but since pages are
added to the workbook as it's updated, i can't have that feature.
Instead, i'll just do a savecopyas within my macro that i use to update
the workbook. The thing is, i don't want them to be able to alter any
data in any cell of the workbook(they don't know vba, so i'm not
worried about them trying to alter code), further more, i don't want
them to be able to save the workbook (which i already have the code for
below), so is there someway to say in vba "if the workbook isn't in
drive I:\ (no matter where it is in drive I:\, as long as it's there)
then make it so that every cell in this workbook is protected
(password=no2cs), and the workbook is unsavable" ...that code wouldn't
go in the macro code, would it?

code for making the workbook unsavable as someone has given me:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
Cancel = True
End Sub

thanks in advance for your help :)

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson

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
Protecting a workbook Kim Excel Worksheet Functions 5 September 29th 08 06:26 PM
protecting workbook jolowe Excel Discussion (Misc queries) 2 June 8th 08 02:57 PM
Protecting a workbook Oldjay Excel Discussion (Misc queries) 1 February 24th 08 08:40 PM
Protecting Workbook!.. Neo1 Excel Worksheet Functions 3 May 3rd 06 01:22 PM
Security - Protecting Macro while generating workbook thru VB 6.0 K.S.Srinivasan Excel Programming 0 January 31st 04 06:36 AM


All times are GMT +1. The time now is 04:32 PM.

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

About Us

"It's about Microsoft Excel"