Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
e e is offline
external usenet poster
 
Posts: 18
Default Novice - using macro to protect with password

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Novice - using macro to protect with password

Hi,

Press Alt + F11 to show the VB Editor window. Find "Book1" or whatever your
workbbok is called, and right-click it to "Insert Module" - paste this into
the module:

Sub demo()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect "blahblah"
Next ws

End Sub

changing "blahblah" to whatever password you want.

That's it.

Sam


"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
e e is offline
external usenet poster
 
Posts: 18
Default Novice - using macro to protect with password

Wow, that seems to be just the ticket! I will try fiddling with it to
customise. Many thanks!

"Sam Wilson" wrote:

Hi,

Press Alt + F11 to show the VB Editor window. Find "Book1" or whatever your
workbbok is called, and right-click it to "Insert Module" - paste this into
the module:

Sub demo()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect "blahblah"
Next ws

End Sub

changing "blahblah" to whatever password you want.

That's it.

Sam


"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Novice - using macro to protect with password

Step by step
1). From Excel --Tools--Macro--Visual Basic Editor
2). From VBE --View--Project Explorer (if not already displayed)
3). Double Click "ThisWorkbook" Module
4). Paste the below

Option Explicit

' Change "Password" to a password of your choice
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Protect "Password", True, True
End Sub

Private Sub Workbook_Open()
Dim QueryUser As String

Const Password As String = "Password"

QueryUser = InputBox("Enter Password", Application.Name)

If QueryUser = Password Then
ThisWorkbook.Unprotect Password
Else
MsgBox "Sorry, No Workbook for you!", vbCritical, Application.Name
ThisWorkbook.Close SaveChanges:=False
End If

End Sub

"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
e e is offline
external usenet poster
 
Posts: 18
Default Novice - using macro to protect with password

Thanks Jeff, but I tried Sam's macro before seeing your message. Sam's seems
to do the trick, but what is the difference between yours? Yours seems much
longer.

"Jeff" wrote:

Step by step
1). From Excel --Tools--Macro--Visual Basic Editor
2). From VBE --View--Project Explorer (if not already displayed)
3). Double Click "ThisWorkbook" Module
4). Paste the below

Option Explicit

' Change "Password" to a password of your choice
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Protect "Password", True, True
End Sub

Private Sub Workbook_Open()
Dim QueryUser As String

Const Password As String = "Password"

QueryUser = InputBox("Enter Password", Application.Name)

If QueryUser = Password Then
ThisWorkbook.Unprotect Password
Else
MsgBox "Sorry, No Workbook for you!", vbCritical, Application.Name
ThisWorkbook.Close SaveChanges:=False
End If

End Sub

"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Novice - using macro to protect with password

You might want to add a second macro to unprotect all sheets:

Sub demo2()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect "blahblah"
Next ws

End Sub

Sam


"E" wrote:

Wow, that seems to be just the ticket! I will try fiddling with it to
customise. Many thanks!

"Sam Wilson" wrote:

Hi,

Press Alt + F11 to show the VB Editor window. Find "Book1" or whatever your
workbbok is called, and right-click it to "Insert Module" - paste this into
the module:

Sub demo()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect "blahblah"
Next ws

End Sub

changing "blahblah" to whatever password you want.

That's it.

Sam


"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.

  #7   Report Post  
Posted to microsoft.public.excel.programming
e e is offline
external usenet poster
 
Posts: 18
Default Novice - using macro to protect with password

Good plan, thanks. I assume 'demo2' is the name of the macro, which I can
change, and then add in a shortcut in the Options menu? (I'm Office 2007.)

"Sam Wilson" wrote:

You might want to add a second macro to unprotect all sheets:

Sub demo2()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect "blahblah"
Next ws

End Sub

Sam


"E" wrote:

Wow, that seems to be just the ticket! I will try fiddling with it to
customise. Many thanks!

"Sam Wilson" wrote:

Hi,

Press Alt + F11 to show the VB Editor window. Find "Book1" or whatever your
workbbok is called, and right-click it to "Insert Module" - paste this into
the module:

Sub demo()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect "blahblah"
Next ws

End Sub

changing "blahblah" to whatever password you want.

That's it.

Sam


"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Novice - using macro to protect with password

Mine just protects the entire workbook, When opened it promts the user for a
password. If its right it unprotect the entire workbook, if not it notifies
the user then closes. Before the worbook closes it protects the workbook
again. Sams Loops through protecting\Unprotecting each sheet one at a time.

"E" wrote:

Thanks Jeff, but I tried Sam's macro before seeing your message. Sam's seems
to do the trick, but what is the difference between yours? Yours seems much
longer.

"Jeff" wrote:

Step by step
1). From Excel --Tools--Macro--Visual Basic Editor
2). From VBE --View--Project Explorer (if not already displayed)
3). Double Click "ThisWorkbook" Module
4). Paste the below

Option Explicit

' Change "Password" to a password of your choice
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Protect "Password", True, True
End Sub

Private Sub Workbook_Open()
Dim QueryUser As String

Const Password As String = "Password"

QueryUser = InputBox("Enter Password", Application.Name)

If QueryUser = Password Then
ThisWorkbook.Unprotect Password
Else
MsgBox "Sorry, No Workbook for you!", vbCritical, Application.Name
ThisWorkbook.Close SaveChanges:=False
End If

End Sub

"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.

  #9   Report Post  
Posted to microsoft.public.excel.programming
e e is offline
external usenet poster
 
Posts: 18
Default Novice - using macro to protect with password

I see. I want users to be able to open the file and use the information, just
not edit it, so I think Sam's is more appropriate for me.
Thank you.

"Jeff" wrote:

Mine just protects the entire workbook, When opened it promts the user for a
password. If its right it unprotect the entire workbook, if not it notifies
the user then closes. Before the worbook closes it protects the workbook
again. Sams Loops through protecting\Unprotecting each sheet one at a time.

"E" wrote:

Thanks Jeff, but I tried Sam's macro before seeing your message. Sam's seems
to do the trick, but what is the difference between yours? Yours seems much
longer.

"Jeff" wrote:

Step by step
1). From Excel --Tools--Macro--Visual Basic Editor
2). From VBE --View--Project Explorer (if not already displayed)
3). Double Click "ThisWorkbook" Module
4). Paste the below

Option Explicit

' Change "Password" to a password of your choice
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Protect "Password", True, True
End Sub

Private Sub Workbook_Open()
Dim QueryUser As String

Const Password As String = "Password"

QueryUser = InputBox("Enter Password", Application.Name)

If QueryUser = Password Then
ThisWorkbook.Unprotect Password
Else
MsgBox "Sorry, No Workbook for you!", vbCritical, Application.Name
ThisWorkbook.Close SaveChanges:=False
End If

End Sub

"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 921
Default Novice - using macro to protect with password

Me too, No Worries.

"E" wrote:

I see. I want users to be able to open the file and use the information, just
not edit it, so I think Sam's is more appropriate for me.
Thank you.

"Jeff" wrote:

Mine just protects the entire workbook, When opened it promts the user for a
password. If its right it unprotect the entire workbook, if not it notifies
the user then closes. Before the worbook closes it protects the workbook
again. Sams Loops through protecting\Unprotecting each sheet one at a time.

"E" wrote:

Thanks Jeff, but I tried Sam's macro before seeing your message. Sam's seems
to do the trick, but what is the difference between yours? Yours seems much
longer.

"Jeff" wrote:

Step by step
1). From Excel --Tools--Macro--Visual Basic Editor
2). From VBE --View--Project Explorer (if not already displayed)
3). Double Click "ThisWorkbook" Module
4). Paste the below

Option Explicit

' Change "Password" to a password of your choice
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Protect "Password", True, True
End Sub

Private Sub Workbook_Open()
Dim QueryUser As String

Const Password As String = "Password"

QueryUser = InputBox("Enter Password", Application.Name)

If QueryUser = Password Then
ThisWorkbook.Unprotect Password
Else
MsgBox "Sorry, No Workbook for you!", vbCritical, Application.Name
ThisWorkbook.Close SaveChanges:=False
End If

End Sub

"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

Thanks.



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Novice - using macro to protect with password

Can you write the macro to ask for you to input the password so it isn't
embedded in the macro?

"Sam Wilson" wrote:

You might want to add a second macro to unprotect all sheets:

Sub demo2()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Unprotect "blahblah"
Next ws

End Sub

Sam


"E" wrote:

Wow, that seems to be just the ticket! I will try fiddling with it to
customise. Many thanks!

"Sam Wilson" wrote:

Hi,

Press Alt + F11 to show the VB Editor window. Find "Book1" or whatever your
workbbok is called, and right-click it to "Insert Module" - paste this into
the module:

Sub demo()

Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Protect "blahblah"
Next ws

End Sub

changing "blahblah" to whatever password you want.

That's it.

Sam


"E" wrote:

I want to protect every sheet in a workbook with a password. I understand
this is tricky, so I will be satisfied if I can write a macro to password
protect every sheet, which will save me typing in the password twice for
every sheet.
I have used macros before by simply recording them, but have no idea how to
write the code myself. Please could someone give me some very simple
instructions how to write an appropriate macro, or edit one I can easily
record.

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
How to Protect MACRO with Password Amol[_3_] Excel Programming 4 August 7th 07 10:40 PM
Password Protect Macro Dan Excel Programming 2 September 1st 06 07:13 PM
password protect macro Modell Excel Programming 3 April 27th 06 08:59 PM
Password Protect Macro? ryanmhess Excel Programming 4 January 27th 06 04:56 PM
Password protect macro Pete Excel Programming 2 April 16th 04 03:44 AM


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