password protection code
Microsoft Office Training verified by visa - mastercard securecode about microsoft training company london ukadd this page to your favourites/bookmarksAdd to favourites
view a printable version of this pagePrintable version
email this page to somebodyEmail this page
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and Help » Password protection code?

Password protection code?

The UK's most regular instructor-led training courses.
Training information: excel microsoft training · Microsoft+excel+training · VBA training in London

resolvedResolved · Low Priority · Version 2003

Password protection code?

Edward has attended:
Excel Introduction course
Excel VBA course
Excel VBA course

by - delegate Edward [1 post] (2008 Jul 22 Tue, 16:11) replyReply

How do I password protect a document using passwords in VBA?

Excel VBA 2 day course
Version Date Location Places
available
Book Next place rate:
Card Invoice
2007 2008 Nov 25 Tue + 26 Wed Bayswater 6 book now £455 £515
2003 2008 Nov 26 Wed + 27 Thu Bloomsbury 2 book now £495 £495
2003 2008 Dec 1 Mon + 2 Tue Bloomsbury 2 book now £495 £495
2003 2008 Dec 4 Thu + 5 Fri Bloomsbury 5 book now £450 £485
2007 2008 Dec 11 Thu + 12 Fri Bayswater 5 book now £475 £515
2007 2009 Jan 8 Thu + 9 Fri Bloomsbury 6 book now £450 £475
Full Schedule: See all 37 Excel VBA course dates.
Bookings currently available until 26th November 2009.

RE: Password protection code?

by - trainer Carlos gold contributer[479 posts] (2008 Jul 24 Thu, 10:50) replyReply

Hi Ed

The code below show you how to password protect multiple worksheets in a workbook. It can easily be adapted to cover all needs

Protecting all sheets with the same password for each sheet

Sub ProtectAllMYSheets()
'This protects all the worksheets with the same password.
'If the worksheet is protected it unprotects it
'You could make this two separate procedures by removing the IF statement; One to protect the other to Unprotect

Dim SheetVar As Worksheet

For Each SheetVar In ActiveWorkbook.Worksheets

If SheetVar.ProtectContents = False Then

SheetVar.Protect Password:="Apple", UserInterfaceOnly:=True

Else

SheetVar.Unprotect Password:="Apple"

End If

Next SheetVar

End Sub


Protecting all sheets with a different password for each sheet

Sub PasswordProtectAllSheets()
'Protect all sheets with a separate password for each
'Again as above: If the worksheet is protected it unprotects it
'You could make this two separate procedures by removing the IF statement; One to protect the other to Unprotect

Dim SheetVar As Worksheet
Dim strPassword As String

For Each SheetVar In ActiveWorkbook.Worksheets

Select Case UCase(SheetVar.CodeName)

Case "SHEET1": strPassword = "Carrot"
Case "SHEET2": strPassword = "Tomato"
Case "SHEET3": strPassword = "Onion"

'Follow pattern :One password for each sheet
'Remember that CodeName always refers to the name the system gives the sheets
'eg Sheet1, Sheet2, etc

'If you have renamed the sheets then replace the reference to Sheet1, etc.
'with the new name and "SheetVar.Name" in the bracket

Case Else: strPassword = "Salad"

End Select


If SheetVar.ProtectContents = False Then

SheetVar.Protect Password:=strPassword, UserInterfaceOnly:=True

Else

SheetVar.Unprotect Password:=strPassword

End If

Next SheetVar

End Sub

Hope this helps you all

Carlos


Related articles

· Basic Excel Training
· Training Budgets In A Bad Economy
· Advanced Excel Training - takes you to the next level
· An Introduction to Microsoft Excel: Top Features for the Excel Novice
· Microsoft Excel Courses Teach Advanced Macro Techniques

Please browse our web site to find out more about
excel microsoft training and other Microsoft training courses.

Excel tip:

Quickly select a block of data

To quickly select a block of data make sure your active cell is somewhere whithin the block of data and then press Ctrl+* or Ctrl+Shift+8.

View all Excel hints and tips

Rate this page:
3.5/5 (2 votes cast)
Institute of IT Training - Accredited Training Provider Microsoft Certified Partner
microsoft office
Microsoft Office Specialist Authorised Testing Centre (MOS and MCAS)

Prodigy Platinum Learning Partner

Institute of IT Training - Accredited Training Provider Association of Computer Trainers Valid HTML 4.01 Transitional
Valid CSS Markup

secure online payments - visa - mastercard

Mini sitemap. These are the main areas of our web site. Full sitemap.

Training by application Main information pages See also

Access courses
DreamWeaver courses
Excel courses
MS Project courses
Outlook courses
PowerPoint courses
VBA courses
Word courses
(more...)

Public scheduled courses
On-site training
Closed company courses

Microsoft Office training
Pricing and availability
Training schedule
Training venues

Access training
Dreamweaver training
Excel training
MS Project training
PowerPoint training

London Computer Training
Computer Training London

Microsoft Access training
Microsoft Excel training
Microsoft Project training
Microsoft Outlook training
Microsoft Powerpoint training
Microsoft Word training

Time Management Course London

Interested in Access training? Please see the following pages:
microsoft access courses · microsoft training access course
microsoft+access+training · access courses in london

Training Information

Training Articles

AddThis Social Bookmark Button What's this?
Add to Del.icio.us Add to Facebook Add to Digg Add to Reddit Add to Google Add to Yahoo Add to Diigo Add to Mr. Wong Add to Linkarena Add to Power Oldie Add to Folkd Add to Jumptags Add to Upchuckr Add to Simpy Add to StumbleUpon Add to Slashdot Add to Netscape Add to Furl Add to Spurl Add to Blinklist Add to Blogmarks Add to Technorati Add to Newsvine Add to Blinkbits Add to Ma.Gnolia Add to Smarking Add to Netvouz