Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Test on Username

Hi There,

I want to test whether the person who wants to open a file is entitled to it
or not ...
I am testing it with the Username in Excel versus an array with Usernames.
The problem is that my code says always that it is a "good user"... even if
the username under ToolsOptionsGeneral is "dfhdgkj"!

Any insight on where I am missing the ball?

Somewhere on the NG I found the code from Norman Jones, so 99% of the credit
goes to him ... the 1% I changed made it work not properly though ;)
Private Sub Workbook_Open()
Dim s As Integer
Dim vh As Integer

Arr = VBA.Array("Guest", "Jim", "Bob", "Norman")
Res = Application.Match(Environ("UserName"), Arr, 0)
If IsError(Res) Then
MsgBox "GOOD user"

Else
MsgBox "BAD user"
End If
End Sub

Thanks for your help!
Jen


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Test on Username

Small Update:

I am aware that Environ("UserName") applies to the WWindows Logon and
Application:USerName for the Username in the Excel application ....

Nevertheless Environ("UserName") should return False ...as my Windows Logon
is nor Guest, Jim, Bob or Norman ...

Any thoughts?
Jen

"Jen" wrote in message
...
Hi There,

I want to test whether the person who wants to open a file is entitled to
it or not ...
I am testing it with the Username in Excel versus an array with Usernames.
The problem is that my code says always that it is a "good user"... even
if the username under ToolsOptionsGeneral is "dfhdgkj"!

Any insight on where I am missing the ball?

Somewhere on the NG I found the code from Norman Jones, so 99% of the
credit goes to him ... the 1% I changed made it work not properly though
;)
Private Sub Workbook_Open()
Dim s As Integer
Dim vh As Integer

Arr = VBA.Array("Guest", "Jim", "Bob", "Norman")
Res = Application.Match(Environ("UserName"), Arr, 0)
If IsError(Res) Then
MsgBox "GOOD user"

Else
MsgBox "BAD user"
End If
End Sub

Thanks for your help!
Jen



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Test on Username


Reversing the test could help ... dooh.
Sorrry! Jen

Private Sub Workbook_Open()
Dim s As Integer
Dim vh As Integer

Arr = VBA.Array("Guest", "Jim", "Bob", "Norman")
'Res = Application.Match(Environ("UserName"), Arr, 0)
Res = Application.Match(Application.UserName, Arr, 0)
If IsError(Res) Then

MsgBox "BAD user"
Else
MsgBox "good user"
End If
End Sub




"Jen" wrote in message
...
Small Update:

I am aware that Environ("UserName") applies to the WWindows Logon and
Application:USerName for the Username in the Excel application ....

Nevertheless Environ("UserName") should return False ...as my Windows
Logon is nor Guest, Jim, Bob or Norman ...

Any thoughts?
Jen

"Jen" wrote in message
...
Hi There,

I want to test whether the person who wants to open a file is entitled to
it or not ...
I am testing it with the Username in Excel versus an array with
Usernames.
The problem is that my code says always that it is a "good user"... even
if the username under ToolsOptionsGeneral is "dfhdgkj"!

Any insight on where I am missing the ball?

Somewhere on the NG I found the code from Norman Jones, so 99% of the
credit goes to him ... the 1% I changed made it work not properly though
;)
Private Sub Workbook_Open()
Dim s As Integer
Dim vh As Integer

Arr = VBA.Array("Guest", "Jim", "Bob", "Norman")
Res = Application.Match(Environ("UserName"), Arr, 0)
If IsError(Res) Then
MsgBox "GOOD user"

Else
MsgBox "BAD user"
End If
End Sub

Thanks for your help!
Jen





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Test on Username

I'm not sure how False fits in (maybe you meant "bad user"??)

But maybe you could debug your code by adding a line and seeing what the VBE
immediate window shows:

Option Explicit
Private Sub Workbook_Open()
Dim res As Variant
Dim Arr As Variant
Arr = Array("Guest", "Jim", "Bob", "Norman")
Debug.Print "***" & Environ("UserName") & "***"
res = Application.Match(Environ("UserName"), Arr, 0)
If IsError(res) Then
MsgBox "GOOD user"
Else
MsgBox "BAD user"
End If
End Sub

If the problem is that you're not getting any message when you open the
workbook, make sure you enable macros for this workbook when/if you're prompted.

And this workbook_open procedure goes behind ThisWorkbook.



Jen wrote:

Small Update:

I am aware that Environ("UserName") applies to the WWindows Logon and
Application:USerName for the Username in the Excel application ....

Nevertheless Environ("UserName") should return False ...as my Windows Logon
is nor Guest, Jim, Bob or Norman ...

Any thoughts?
Jen

"Jen" wrote in message
...
Hi There,

I want to test whether the person who wants to open a file is entitled to
it or not ...
I am testing it with the Username in Excel versus an array with Usernames.
The problem is that my code says always that it is a "good user"... even
if the username under ToolsOptionsGeneral is "dfhdgkj"!

Any insight on where I am missing the ball?

Somewhere on the NG I found the code from Norman Jones, so 99% of the
credit goes to him ... the 1% I changed made it work not properly though
;)
Private Sub Workbook_Open()
Dim s As Integer
Dim vh As Integer

Arr = VBA.Array("Guest", "Jim", "Bob", "Norman")
Res = Application.Match(Environ("UserName"), Arr, 0)
If IsError(Res) Then
MsgBox "GOOD user"

Else
MsgBox "BAD user"
End If
End Sub

Thanks for your help!
Jen


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Test on Username

Oops. I didn't see your reply.

Jen wrote:

Reversing the test could help ... dooh.
Sorrry! Jen

Private Sub Workbook_Open()
Dim s As Integer
Dim vh As Integer

Arr = VBA.Array("Guest", "Jim", "Bob", "Norman")
'Res = Application.Match(Environ("UserName"), Arr, 0)
Res = Application.Match(Application.UserName, Arr, 0)
If IsError(Res) Then

MsgBox "BAD user"
Else
MsgBox "good user"
End If
End Sub

"Jen" wrote in message
...
Small Update:

I am aware that Environ("UserName") applies to the WWindows Logon and
Application:USerName for the Username in the Excel application ....

Nevertheless Environ("UserName") should return False ...as my Windows
Logon is nor Guest, Jim, Bob or Norman ...

Any thoughts?
Jen

"Jen" wrote in message
...
Hi There,

I want to test whether the person who wants to open a file is entitled to
it or not ...
I am testing it with the Username in Excel versus an array with
Usernames.
The problem is that my code says always that it is a "good user"... even
if the username under ToolsOptionsGeneral is "dfhdgkj"!

Any insight on where I am missing the ball?

Somewhere on the NG I found the code from Norman Jones, so 99% of the
credit goes to him ... the 1% I changed made it work not properly though
;)
Private Sub Workbook_Open()
Dim s As Integer
Dim vh As Integer

Arr = VBA.Array("Guest", "Jim", "Bob", "Norman")
Res = Application.Match(Environ("UserName"), Arr, 0)
If IsError(Res) Then
MsgBox "GOOD user"

Else
MsgBox "BAD user"
End If
End Sub

Thanks for your help!
Jen




--

Dave Peterson
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
(username v1) JJernigan Excel Discussion (Misc queries) 0 June 12th 08 09:13 PM
Calculate mean of test scores from rows of test answers RiotLoadTime Excel Discussion (Misc queries) 1 July 26th 06 05:14 PM
Username Log PaulJ Excel Discussion (Misc queries) 8 March 1st 06 11:51 AM
NT Username ceemo Excel Discussion (Misc queries) 4 August 2nd 05 04:39 PM
Username Lawlera[_2_] Excel Programming 3 December 23rd 03 09:21 AM


All times are GMT +1. The time now is 03:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"