Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Help with VB Script

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Help with VB Script

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

--
Gary''s Student - gsnu200786
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 638
Default Help with VB Script

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

On May 14, 2:00*pm, Storm wrote:
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Help with VB Script

Thank you!

"Gary''s Student" wrote:

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

--
Gary''s Student - gsnu200786

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Help with VB Script

Thank you!

"JW" wrote:

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

On May 14, 2:00 pm, Storm wrote:
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



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
Help ! How do I do this in VB Script Sean Setting up and Configuration of Excel 3 March 17th 08 12:16 PM
VB Script Steph[_3_] Excel Programming 3 June 1st 05 04:49 PM
vba script help anthony Excel Programming 2 May 8th 05 06:42 PM
Help with VB script please? Peter[_28_] Excel Programming 5 October 13th 04 11:49 PM
Excel 2000/XP script to Excel97 script hat Excel Programming 3 March 2nd 04 03:56 PM


All times are GMT +1. The time now is 03:47 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"