![]() |
Use % as variable for user id?
Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on
their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
Not sure exactly what you want but the following user-defined-function can be
used to get the Network User Name. Just run the 'ShowNetName' macro... '/=================================================/ Private Declare Function GetUserName Lib "ADVAPI32.DLL" _ Alias "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long '/=================================================/ Sub ShowNetName() MsgBox GetNetworkUserName End Sub '/=================================================/ Private Function GetNetworkUserName() As String Dim strUserName As String On Error GoTo Err_GetNetworkUserName strUserName = String(255, 0) GetUserName strUserName, Len(strUserName) GetNetworkUserName = Application.WorksheetFunction. _ Clean(strUserName) Exit_GetNetworkUserName: Exit Function Err_GetNetworkUserName: GetNetworkUserName = "" Resume Exit_GetNetworkUserName End Function '/=================================================/ HTH, -- Gary Brown If this post was helpful, please click the ''Yes'' button next to ''Was this Post Helpfull to you?''. "R. Choate" wrote: Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
What I needed was the simple
strUser = Environ("username") that yields whatever the user is logged on as. I think this is likely the same info returned by the long API call you referenced, but I'm not sure. Thanks, -- RMC,CPA "Gary L Brown" wrote in message ... Not sure exactly what you want but the following user-defined-function can be used to get the Network User Name. Just run the 'ShowNetName' macro... '/=================================================/ Private Declare Function GetUserName Lib "ADVAPI32.DLL" _ Alias "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long '/=================================================/ Sub ShowNetName() MsgBox GetNetworkUserName End Sub '/=================================================/ Private Function GetNetworkUserName() As String Dim strUserName As String On Error GoTo Err_GetNetworkUserName strUserName = String(255, 0) GetUserName strUserName, Len(strUserName) GetNetworkUserName = Application.WorksheetFunction. _ Clean(strUserName) Exit_GetNetworkUserName: Exit Function Err_GetNetworkUserName: GetNetworkUserName = "" Resume Exit_GetNetworkUserName End Function '/=================================================/ HTH, -- Gary Brown If this post was helpful, please click the ''Yes'' button next to ''Was this Post Helpfull to you?''. "R. Choate" wrote: Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
Just use
Environ("UserName") to get the network login name. -- HTH Bob Phillips (remove nothere from the email address if mailing direct) "R. Choate" wrote in message ... Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
If I recall correctly, older versions of Windows (98? ME?) don't
have the "username" environ variable. The API method will work in any version. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "R. Choate" wrote in message ... What I needed was the simple strUser = Environ("username") that yields whatever the user is logged on as. I think this is likely the same info returned by the long API call you referenced, but I'm not sure. Thanks, -- RMC,CPA "Gary L Brown" wrote in message ... Not sure exactly what you want but the following user-defined-function can be used to get the Network User Name. Just run the 'ShowNetName' macro... '/=================================================/ Private Declare Function GetUserName Lib "ADVAPI32.DLL" _ Alias "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long '/=================================================/ Sub ShowNetName() MsgBox GetNetworkUserName End Sub '/=================================================/ Private Function GetNetworkUserName() As String Dim strUserName As String On Error GoTo Err_GetNetworkUserName strUserName = String(255, 0) GetUserName strUserName, Len(strUserName) GetNetworkUserName = Application.WorksheetFunction. _ Clean(strUserName) Exit_GetNetworkUserName: Exit Function Err_GetNetworkUserName: GetNetworkUserName = "" Resume Exit_GetNetworkUserName End Function '/=================================================/ HTH, -- Gary Brown If this post was helpful, please click the ''Yes'' button next to ''Was this Post Helpfull to you?''. "R. Choate" wrote: Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
When will they be differnt Gary, assuming that the OS supports it?
-- HTH Bob Phillips (remove nothere from the email address if mailing direct) "Gary L Brown" wrote in message ... Yes and No. :O Environ gives you the user name for the Windows login. The function I supplied gives the user name for the network login. They are almost always the same but can be different. That's why the 'yes' and 'no' answer. Hope one of the solutions supplied is what you are looking for. Sincerely, -- Gary Brown If this post was helpful, please click the ''Yes'' button next to ''Was this Post Helpfull to you?''. "R. Choate" wrote: What I needed was the simple strUser = Environ("username") that yields whatever the user is logged on as. I think this is likely the same info returned by the long API call you referenced, but I'm not sure. Thanks, -- RMC,CPA "Gary L Brown" wrote in message ... Not sure exactly what you want but the following user-defined-function can be used to get the Network User Name. Just run the 'ShowNetName' macro... '/=================================================/ Private Declare Function GetUserName Lib "ADVAPI32.DLL" _ Alias "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long '/=================================================/ Sub ShowNetName() MsgBox GetNetworkUserName End Sub '/=================================================/ Private Function GetNetworkUserName() As String Dim strUserName As String On Error GoTo Err_GetNetworkUserName strUserName = String(255, 0) GetUserName strUserName, Len(strUserName) GetNetworkUserName = Application.WorksheetFunction. _ Clean(strUserName) Exit_GetNetworkUserName: Exit Function Err_GetNetworkUserName: GetNetworkUserName = "" Resume Exit_GetNetworkUserName End Function '/=================================================/ HTH, -- Gary Brown If this post was helpful, please click the ''Yes'' button next to ''Was this Post Helpfull to you?''. "R. Choate" wrote: Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
Hi Bob
If one is only interested in the user of the Excel application being run, are there any merits of Environ("UserName") over application.username I have only ever used the latter, but by chance happened to come across the use of Environ variables elsewhere whilst researching something today. I have no idea of the differences. -- Regards Roger Govier "Bob Phillips" wrote in message ... Just use Environ("UserName") to get the network login name. -- HTH Bob Phillips (remove nothere from the email address if mailing direct) "R. Choate" wrote in message ... Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
Thanks. I'm going to use environ. That will work on my OS and that of all of my users.
-- RMC,CPA "Gary L Brown" wrote in message ... Yes and No. :O Environ gives you the user name for the Windows login. The function I supplied gives the user name for the network login. They are almost always the same but can be different. That's why the 'yes' and 'no' answer. Hope one of the solutions supplied is what you are looking for. Sincerely, -- Gary Brown If this post was helpful, please click the ''Yes'' button next to ''Was this Post Helpfull to you?''. "R. Choate" wrote: What I needed was the simple strUser = Environ("username") that yields whatever the user is logged on as. I think this is likely the same info returned by the long API call you referenced, but I'm not sure. Thanks, -- RMC,CPA "Gary L Brown" wrote in message ... Not sure exactly what you want but the following user-defined-function can be used to get the Network User Name. Just run the 'ShowNetName' macro... '/=================================================/ Private Declare Function GetUserName Lib "ADVAPI32.DLL" _ Alias "GetUserNameA" (ByVal lpBuffer As String, _ nSize As Long) As Long '/=================================================/ Sub ShowNetName() MsgBox GetNetworkUserName End Sub '/=================================================/ Private Function GetNetworkUserName() As String Dim strUserName As String On Error GoTo Err_GetNetworkUserName strUserName = String(255, 0) GetUserName strUserName, Len(strUserName) GetNetworkUserName = Application.WorksheetFunction. _ Clean(strUserName) Exit_GetNetworkUserName: Exit Function Err_GetNetworkUserName: GetNetworkUserName = "" Resume Exit_GetNetworkUserName End Function '/=================================================/ HTH, -- Gary Brown If this post was helpful, please click the ''Yes'' button next to ''Was this Post Helpfull to you?''. "R. Choate" wrote: Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
application.username
This line of code retrieves the value from Tools - Options - General tab - User Name. This value is at the discression of the user. They could change it to any value that they want. Because of that I personally never use this. Environ("UserName") Retrieves the user name that the person logged into their computer with. This is managed by the operating system and the end user generally speaking has no control over it. This is handy for validating who is using your spreadsheet and granting them the appropriate access, among other things. I use this all of the time, unless I am developing for multiple platforms where I tend to use the API shown by Gary. -- HTH... Jim Thomlinson "Roger Govier" wrote: Hi Bob If one is only interested in the user of the Excel application being run, are there any merits of Environ("UserName") over application.username I have only ever used the latter, but by chance happened to come across the use of Environ variables elsewhere whilst researching something today. I have no idea of the differences. -- Regards Roger Govier "Bob Phillips" wrote in message ... Just use Environ("UserName") to get the network login name. -- HTH Bob Phillips (remove nothere from the email address if mailing direct) "R. Choate" wrote in message ... Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
plus, when installing office at my large clients, there is either a master
mst file, or a sysprep file for windows. or i use the main person's name at the client if i'm adding an installation manually. i have no idea who is going to be using a particular pc, so windows and office almost always have the same person's name, not the user's name. so, environ("username") is the only option for me. -- Gary "Jim Thomlinson" wrote in message ... application.username This line of code retrieves the value from Tools - Options - General tab - User Name. This value is at the discression of the user. They could change it to any value that they want. Because of that I personally never use this. Environ("UserName") Retrieves the user name that the person logged into their computer with. This is managed by the operating system and the end user generally speaking has no control over it. This is handy for validating who is using your spreadsheet and granting them the appropriate access, among other things. I use this all of the time, unless I am developing for multiple platforms where I tend to use the API shown by Gary. -- HTH... Jim Thomlinson "Roger Govier" wrote: Hi Bob If one is only interested in the user of the Excel application being run, are there any merits of Environ("UserName") over application.username I have only ever used the latter, but by chance happened to come across the use of Environ variables elsewhere whilst researching something today. I have no idea of the differences. -- Regards Roger Govier "Bob Phillips" wrote in message ... Just use Environ("UserName") to get the network login name. -- HTH Bob Phillips (remove nothere from the email address if mailing direct) "R. Choate" wrote in message ... Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
Use % as variable for user id?
Hi Jim & Gary
Thanks for the response. I can see that the Environ option is by far the safer and, as in this particular application, there will be use of different templates according to various usernames, then this will be the better option for me. Obviously, anyone could just change their user name in Excel, close and re-open and could gain easy access to the wrong files. I am most grateful to you both. -- Regards Roger Govier "Gary Keramidas" <GKeramidasATmsn.com wrote in message ... plus, when installing office at my large clients, there is either a master mst file, or a sysprep file for windows. or i use the main person's name at the client if i'm adding an installation manually. i have no idea who is going to be using a particular pc, so windows and office almost always have the same person's name, not the user's name. so, environ("username") is the only option for me. -- Gary "Jim Thomlinson" wrote in message ... application.username This line of code retrieves the value from Tools - Options - General tab - User Name. This value is at the discression of the user. They could change it to any value that they want. Because of that I personally never use this. Environ("UserName") Retrieves the user name that the person logged into their computer with. This is managed by the operating system and the end user generally speaking has no control over it. This is handy for validating who is using your spreadsheet and granting them the appropriate access, among other things. I use this all of the time, unless I am developing for multiple platforms where I tend to use the API shown by Gary. -- HTH... Jim Thomlinson "Roger Govier" wrote: Hi Bob If one is only interested in the user of the Excel application being run, are there any merits of Environ("UserName") over application.username I have only ever used the latter, but by chance happened to come across the use of Environ variables elsewhere whilst researching something today. I have no idea of the differences. -- Regards Roger Govier "Bob Phillips" wrote in message ... Just use Environ("UserName") to get the network login name. -- HTH Bob Phillips (remove nothere from the email address if mailing direct) "R. Choate" wrote in message ... Can I initialize the % sign as a variable in code to identify and use to indicate the user id of the user who is running the code on their station? For example X = %. or something like that. Thanks, -- RMC,CPA |
All times are GMT +1. The time now is 02:42 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com