#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default username

Hi

Is there any way of preventing a user from changing the
Application.UserName via the Tools/Options/General.

I have a macro that performs certain code depending on
who's logged on.
I'm running Windows NT which people have to log onto so is
there any way Excel97 can look at that login and use that
as the username???
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default username

Libby,

There is no way to prevent the user from changing the username in
the Options dialog. You can get the Windows logon name with code
like:

Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long

Sub AAA()
Dim UName As String * 255
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
Msgbox UName
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"libby" wrote in message
...
Hi

Is there any way of preventing a user from changing the
Application.UserName via the Tools/Options/General.

I have a macro that performs certain code depending on
who's logged on.
I'm running Windows NT which people have to log onto so is
there any way Excel97 can look at that login and use that
as the username???



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default username

Thanks Chip :o)

Is it possible to change the username to the windows logon
name programmatically, whenever a button on a sheet is
clicked?
That way, even if the user had changed the username, it
would be changed back when the button was clicked and so
run the correct macro.


-----Original Message-----
Libby,

There is no way to prevent the user from changing the

username in
the Options dialog. You can get the Windows logon name

with code
like:

Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long

Sub AAA()
Dim UName As String * 255
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
Msgbox UName
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"libby" wrote in

message
...
Hi

Is there any way of preventing a user from changing the
Application.UserName via the Tools/Options/General.

I have a macro that performs certain code depending on
who's logged on.
I'm running Windows NT which people have to log onto so

is
there any way Excel97 can look at that login and use

that
as the username???



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default username

Libby,

Once you have the Windows logon name and described in my previous
reply, you can use that to change Excel's username property.

Application.UserName = UName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Libby" wrote in message
...
Thanks Chip :o)

Is it possible to change the username to the windows logon
name programmatically, whenever a button on a sheet is
clicked?
That way, even if the user had changed the username, it
would be changed back when the button was clicked and so
run the correct macro.


-----Original Message-----
Libby,

There is no way to prevent the user from changing the

username in
the Options dialog. You can get the Windows logon name

with code
like:

Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long

Sub AAA()
Dim UName As String * 255
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
Msgbox UName
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"libby" wrote in

message
...
Hi

Is there any way of preventing a user from changing the
Application.UserName via the Tools/Options/General.

I have a macro that performs certain code depending on
who's logged on.
I'm running Windows NT which people have to log onto so

is
there any way Excel97 can look at that login and use

that
as the username???



.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default username runtime error

Hi Chip

That works if I step through the code but when I call the
macro from a button on the sheet I get a runtime error
Method 'Username' of object_Application failed

-----Original Message-----
Libby,

Once you have the Windows logon name and described in my

previous
reply, you can use that to change Excel's username

property.

Application.UserName = UName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Libby" wrote in

message
...
Thanks Chip :o)

Is it possible to change the username to the windows

logon
name programmatically, whenever a button on a sheet is
clicked?
That way, even if the user had changed the username, it
would be changed back when the button was clicked and

so
run the correct macro.


-----Original Message-----
Libby,

There is no way to prevent the user from changing the

username in
the Options dialog. You can get the Windows logon name

with code
like:

Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long

Sub AAA()
Dim UName As String * 255
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
Msgbox UName
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"libby" wrote in

message
...
Hi

Is there any way of preventing a user from changing

the
Application.UserName via the Tools/Options/General.

I have a macro that performs certain code depending

on
who's logged on.
I'm running Windows NT which people have to log onto

so
is
there any way Excel97 can look at that login and use

that
as the username???


.



.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default username runtime error

Libby,

In design mode, right click on the command button and choose
Properties. In that dialog, change the TakeFocusOnClick property
to False.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"libby" wrote in message
...
Hi Chip

That works if I step through the code but when I call the
macro from a button on the sheet I get a runtime error
Method 'Username' of object_Application failed

-----Original Message-----
Libby,

Once you have the Windows logon name and described in my

previous
reply, you can use that to change Excel's username

property.

Application.UserName = UName


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Libby" wrote in

message
...
Thanks Chip :o)

Is it possible to change the username to the windows

logon
name programmatically, whenever a button on a sheet is
clicked?
That way, even if the user had changed the username, it
would be changed back when the button was clicked and

so
run the correct macro.


-----Original Message-----
Libby,

There is no way to prevent the user from changing the
username in
the Options dialog. You can get the Windows logon name
with code
like:

Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" ( _
ByVal lpBuffer As String, nSize As Long) As Long

Sub AAA()
Dim UName As String * 255
Dim L As Long: L = 255
Dim Res As Long
Res = GetUserName(UName, L)
UName = Left$(UName, L - 1)
Msgbox UName
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"libby" wrote in
message
...
Hi

Is there any way of preventing a user from changing

the
Application.UserName via the Tools/Options/General.

I have a macro that performs certain code depending

on
who's logged on.
I'm running Windows NT which people have to log onto

so
is
there any way Excel97 can look at that login and use
that
as the username???


.



.



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default username runtime error


Hi Chip

I don't fully understand your code (even though it works).
When I step through it and find the Windows Logon name
which is say, "Libby", there are a lot of additional
characters. "Libby|||||||||||||"
This means that if I then make UName the
Application.UserName then my code

Select Case Application.Username
Case "Libby"
etc

doesn't work since there are x number of additional
characters after.
Is there any way that only the "Libby" bit can be used for
the application.username?

Thanks :o)

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default username runtime error

Hi Libby,

Are you using the Left$ function as I showed in the example?


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Libby" wrote in message
...

Hi Chip

I don't fully understand your code (even though it works).
When I step through it and find the Windows Logon name
which is say, "Libby", there are a lot of additional
characters. "Libby|||||||||||||"
This means that if I then make UName the
Application.UserName then my code

Select Case Application.Username
Case "Libby"
etc

doesn't work since there are x number of additional
characters after.
Is there any way that only the "Libby" bit can be used for
the application.username?

Thanks :o)



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default username runtime error

Chip,

Once again your detailed explanations have helped me out on a annoying
problem, thanks so much !

Yours sincerely,

Brent McIntyre

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
username robzrob Excel Worksheet Functions 2 May 4th 08 05:59 PM
NT Username ceemo Excel Discussion (Misc queries) 4 August 2nd 05 04:39 PM
Get NT Username Steven Pugh Excel Programming 7 February 20th 04 09:37 AM
Username Lawlera[_2_] Excel Programming 3 December 23rd 03 09:21 AM


All times are GMT +1. The time now is 02:39 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"