macro question

Colo

MrExcel MVP,
Joined
Mar 20, 2002
Messages
1,659
Office Version
  1. 2016
  2. 2003 or older
Platform
  1. Windows
Hi. Why don't you use visible properties of worksheets.
In order to display the sheet, an user must use vba.
So like this time, I always use this properties.
Please describe the following code to ThisWorkbook module.
I assume that Sheet2 is a data sheet.
Please change a sheet name according to your environment.


'ThisWorkbook module-----------from here---------------
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Const pwd As String = "1111"
If Sh.Name <> "Sheet1" Then Exit Sub
If InputBox("Password Please") <> pwd Then Exit Sub
With Sheets("Sheet2")
.Visible = xlSheetVisible
Application.Goto .Cells(1.1)
End With
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
If Sh.Name <> "Sheet2" Then Exit Sub
Sheets("Sheet2").Visible = xlSheetVeryHidden
End Sub
'------------------------------to here------------------
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I have a worksheet I keep the data hidden on. When the sheet is activated an input box asks for a password then the sheet is activated and the data seen. What I'm wanting is to add code to a macro that will unprotect the sheet so the macro can finish and then leave the sheet activated. I think I explained it okay.

I have a macro that will activate sheet 1 do its thing then activate the hidden sheet, my problem is that I'm using the input box and code to protect the sheet and not just the tools>protect sheet so I'm running into errors when I put ActiveSheet.Unprotect ("password") in my code. How can I supply the input box the password using a macro?
 
Upvote 0

Forum statistics

Threads
1,213,538
Messages
6,114,218
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top