Display current sheet name being processed in macro

A

Ann

I have the following macro that will protect each sheet in a workbook.

For n = 1 To Sheets.Count
'Sheets(n).Protect Password:="&PasswordEntered"
Title = "Protecting sheet"
Style = vbInformation
MsgBox "Sheet Protected ", Style, Title
Next n

I need to display the sheet name back to the user, can someone suggest how I
do that within the macro along with the msgbox?
 
M

Mike

Try your macro altered like this:-

Sub protect()
For n = 1 To Sheets.Count
Sheets(n).protect 'Password:="&PasswordEntered"

Title = "Protecting sheet"
Style = vbInformation
Message = ActiveSheet.Name & " Protected"
MsgBox Message, Style, Title
Next n
End Sub

Mike
 
M

Mike

OOPS missed a line

Sub protect()
For n = 1 To Sheets.Count

Sheets(n).protect 'Password:="&PasswordEntered"
Sheets(n).Select
Title = "Protecting sheet"
Style = vbInformation
Message = ActiveSheet.Name & " Protected"
MsgBox Message, Style, Title
Next n
End Sub
 
A

Ann

Mike,

I copied your code and it displays the Active Sheet Name (say sheet1) every
time.

I want the macro to display the sheet name as it goes through the workbook.

Any ideas?
 
J

JE McGimpsey

One way:

Dim n As Long
For n = 1 To Sheets.Count
With Sheets(n)
.Protect Password:="&PasswordEntered"
MsgBox Prompt:= .Name & " Protected", _
Title:="Protecting Sheet", _
Buttons:=vbInformation
End WIth
Next n
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top