View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Kelly[_3_] Kelly[_3_] is offline
external usenet poster
 
Posts: 8
Default Returning User Initials

Well, It seemed to work fine when the user opened the
template on their own PC logged in as themselves. So
that's fine but If another user logged in ...(i.e. if I
log in on another users PC) then it's like the code does
not even run? There are no errors but the code does not
return any initials at all.(we use initials as log in
ID) . I will include the code as I used it and how I set
it up to run. Maybe you can spot my problem....And thanks
again I really appreciate your help..




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



Private Sub Workbook_Activate()
If ThisWorkbook.Path = "" Then
' code to run when template is opened

Dim lpBuff As String * 25
Dim ret As Long, UserName As String

' Get the user name minus any trailing spaces found in the
name.
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)

Sheets("Control").Unprotect Password:="test"

Worksheets("Control").Range("L1").Value = UserName

Worksheets("Control").Range("A19").Value = Worksheets
("Control").Range("A17").Value

Sheets("Control").Protect Password:="test"


End If

End Sub



-----Original Message-----
keep in mind that the code I sent is in 2 parts. The

first part is the
declaration part for the API call. The next part is the

subroutine for
grabbing the users windows login name. What sort of

trouble did you have?
--
HTH
Richard Choate, CPA

"Kelly" wrote in message
...
Hi all, thanks again for some great advice.

Dave I think if I can make the Log In Id solution work
then that will be the way to go, But thanks I now know how
to return Word info.

John, Thanks, I do relize that Excel is not real secure
but I think if I can at least make this sheet secure
against a simple change of the tools/options/general Name
I'll feel a little better. Also If i can get this to work
then users can fill out their expense cards on any PC they
log on to.

Richard..

Thanks for the great code but I am still having a little
trouble, hope you don't mind more questions?

Any way I set up the code to run in and on activate event
and it works fine to bring up MY windows log in id on MY
PC. But when somone eles signs onto my pc and opens the
spreadsheet it appears to not even run? Well at least it
does not return MY Login id but it won't return any log in
id though??

Any futher ideas? Also when I place the template on a
common user network and other users access it on there own
PC it works for them but still only if they are logged
into there own PC.

????
-----Original Message-----
Thanks to you both. Your advice did help me to understand
a little better but unfortunaly (or fortunaltley

depending
how you look at it) I also now relize the code I build is
not as secure or as reliable as I firt thought.

First of all good advice Jhon but I need all three
initials and it appears company standards were to only
enter the first and last name of the employee when
installing Office.

Secondly I found a way to break into my spreadsheet to
read information that was not meant for me.

See the way I had set it up is that when you opened the
template it would automaticly find the Application .user
and based on this prefor a bunch of V-look ups on a
verryhidden conrtol sheet. Now I realize that the user
only has to change the info in his General options to

look
at other users info.

I know that it is not real secure as a hidden sheet but I
think more so then this. Also I did a little testing and
if there is even an extra space in the info under general
options then the v-lookup crashes.

As far as the initals, I just added anonther column to my
hidden sheet and added another v-lookup to access the
initials but I am a little worried about the other issues
now.

Any other suggestions as to how to return PC user
information? I would like to be able to referance the
users Windows log-on ID but have no idea to do that?

Thanks for all your help.

Kelly





-----Original Message-----
Hi all, I am using the Office 2000 package

In Word VB you can return user initials
with "Application.UserInitials"

Is there any way to do this in Excel?

I know you can return user name
with "Application.UserName" but no luck with initials so
far.

Also Where does the user name info come from anyway?
In "Word" it is entered in tools/Options/UserInformation
but I have no idea for Excel.


Thanks as always!

Kelly
.

.



.