ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Track Changes Username with Windows (https://www.excelbanter.com/excel-discussion-misc-queries/137423-track-changes-username-windows.html)

Trying to Excel

Track Changes Username with Windows
 
I am not familiar with Visual Basic and have a basic knowledge of Macros.

I am using a shared workbook with multiple users on one computer as well as
single users on other computers.

Is there a way to track changes with the users Window log on ID as the
username in Excel? The company name appears in the General tab username when
each user logs in as it was entered when the program was installed. It is
impractical to log each user on and changing the username in Excel after they
have logged in.

I am aware there was another post refering to this but it did not work for
me. This may be a result of my inexperience with VB. Your help, as always is
greatly appreciated.

Dave Peterson

Track Changes Username with Windows
 
I don't think you can change that behavior.

But you could send out an excel file that updates that Username based on their
login name.

Option Explicit
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Declare Function apiGetComputerName Lib "kernel32" Alias _
"GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX < 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function
Sub auto_Open()

Dim myWindowsName As String
Dim myExcelName As String

myWindowsName = fOSUserName
myExcelName = Application.UserName

If LCase(myExcelName) = LCase("Yourcompanynamehere") Then
'change the name
Application.UserName = myWindowsName
End If

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

This will only change the username if the existing tools|Options|General tab
username matches what you type in this spot: Yourcompanynamehere

Otherwise, it leaves the user name alone.



Trying to Excel wrote:

I am not familiar with Visual Basic and have a basic knowledge of Macros.

I am using a shared workbook with multiple users on one computer as well as
single users on other computers.

Is there a way to track changes with the users Window log on ID as the
username in Excel? The company name appears in the General tab username when
each user logs in as it was entered when the program was installed. It is
impractical to log each user on and changing the username in Excel after they
have logged in.

I am aware there was another post refering to this but it did not work for
me. This may be a result of my inexperience with VB. Your help, as always is
greatly appreciated.


--

Dave Peterson


All times are GMT +1. The time now is 10:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com