Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / May 2008

Tip: Looking for answers? Try searching our database.

Help with VB Script

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Storm - 14 May 2008 19:00 GMT
Hello.

I have a Macro (VB script) that will help me protect all worksheets within a
workbook.  It prompts for the password to protect all sheets when the Macro
is run.

Can someone help me revise the code below where only 2 worksheets are
protected out of a 3-worksheet workbook?  Thank you!

Sub Protect()
 Dim myPWD As String
 Dim wks As Worksheet
 myPWD = Application.InputBox("Enter Password: ")
 For Each wks In ActiveWorkbook.Worksheets
   wks.Protect Password:=myPWD
 Next wks
End Sub
Gary''s Student - 14 May 2008 19:09 GMT
Sub Protect()
 Dim myPWD As String
 Dim wks As Worksheet
 myPWD = Application.InputBox("Enter Password: ")
 i = 0
 For Each wks In ActiveWorkbook.Worksheets
   wks.Protect Password:=myPWD
   i = i + 1
   If i = 2 Then Exit Sub
 Next wks
End Sub

Signature

Gary''s Student - gsnu200786

Storm - 14 May 2008 21:12 GMT
Thank you!

> Sub Protect()
>   Dim myPWD As String
[quoted text clipped - 7 lines]
>   Next wks
> End Sub
JW - 14 May 2008 19:09 GMT
replace "the one you want to exclude" with whatever the name of the
sheet is that you want to exclude.

Sub Protect()
 Dim myPWD As String
 Dim wks As Worksheet
 myPWD = Application.InputBox("Enter Password: ")
 For Each wks In ActiveWorkbook.Worksheets
   If wks.Name <> "the one you want to exclude" Then _
       wks.Protect Password:=myPWD
 Next wks
End Sub

> Hello.
>
[quoted text clipped - 13 lines]
>   Next wks
> End Sub
Storm - 14 May 2008 21:12 GMT
Thank you!

> replace "the one you want to exclude" with whatever the name of the
> sheet is that you want to exclude.
[quoted text clipped - 26 lines]
> >   Next wks
> > End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.