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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SetFocus depending on user

Status
Not open for further replies.

Diezz

Technical User
Dec 24, 2004
61
NL
Hello,

As login for windows we use code numbers, for example mine is "701000602".

There are others who use the same workbook as i am and i would like them to set focus on different cells.
This is what i've tried for myself :

"Private Sub Workbook_Open()
If Environ("701000602") Then
Worksheets("Sheet1").Cells(5, 3).SetFocus
End If"

However when i open the workbook : error.

Did i miss something?
 
Diezz

Try

Sub env_test()
for x=1 to 29
msgbox(x & ": " & environ(x))
next x
end sub

This will show you the different outputs for the environ function. You will find the computer or user name when the correct parameter is used.

Identify the parameter and then use it in your code, i.e.

If Environ(10) = "701000602" Then....

In your code you are using a parameter outside of the function's scope.

HTH

 
If you are trying to use the username (the Windows login name), then it is Environ("Username"). Also, the IF statement needs to have a value to check against. Try:
Code:
If Environ("Username") = "701000602" Then
    Worksheets("Sheet1").Cells(5, 3).SetFocus
End If

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top