Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXCEL : which sheet did I come from ?

Status
Not open for further replies.

chandlm

Programmer
Feb 11, 2003
114
GB
Can anyone point me in the right direction as to display the sheet name that I have just come from when I change sheets.

Also does anyone know if you can set permissions for a single sheet for 2 certain users, so that only the permitted user can view the sheet.
 
Chandlm in answer to your first query, may I suggest that you try one of the following:
While on the sheet whose name you need..
Name = Activesheet.name

If you are on another sheet...
Name = Worksheets(x).name (where x = index number of the sheet)

The answer to question2 is one I will leave for some other more clued up individual...
[thumbsup]
 
Hello,

A while back, I put together a demo workbook addressing this issue for another Tek-Tips poster. If you would like a copy, post your email. In the meantime, I'll dust it off and makes some notes on its use.


Regards,
Mike
 
The 2nd part of the query can be handled with the sheet ACTIVATE event

If you are on an NT network, you can use
mUser = environ("username") to get the id of the current user so within the Sheet_Activate event, you could use something like:

Private Sub Worksheet_Activate()
mUser = Environ("username")
Select Case mUser
Case "user1", "user2"
Exit Sub
Case Else
MsgBox "You do not have permission to use this sheet"
Sheets(sht).Select
sheets(sht).Range("a1").Select
End Select
End Sub

This would need to be set up with sht declared as a public variable (string) and this code in the sheet_deactivate code of all the other worksheets:

Private Sub Worksheet_Deactivate()
sht = Me.Name
End Sub


Skip - I may be being incredibly thick but how does the code you provided work - doesn't seem to be fired when the sheet is deactivated....

Stoffel24 - unfortunately, you cannot use activesheet.name as the sheet has been DEactivated - you tyherefore have to use Me.Name as the parent object is still the sheet that has just been deactivated Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
aaaaah - doesn't work on '97 :-( Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Geoff,

On XL 2000 Skip's solution works. I have 97 at home and will try it there. I can't see what would have changed from 97 to 2000 regarding this event procedure to allow this to work where it hadn't before.

Mike
 
oh my life !!! How embarrassed am I ? [blush]
I put it in the sheet module accidentally rather than the workbook module - no wonder it didn't run
[hammer] Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Geoff,

Ok, Ok. I admit it. I initially did the same thing but didn't mention it because I was sure it was my silliness only. [blush]


Mike
 
LOL LOL LOL Rgds
Geoff
"Some cause happiness wherever they go; others whenever they go."
-Oscar Wilde
 
Thanks xlbo That was just the push I needed.

Thanks to all others that have posted a response.

Thank god for
Humbly in your shadows.

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top