Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capitalise
Hi
I have a great function in VBA which returns the network login name. I use this simply to add the user name to emails. Unfortunately the name is returned in lower case, which doesn't look as good as it could. Is there a way to ensure the name returned is correctly capitalised. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capitalise
Richard,
Try this line fOSUserName = UCase(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Hi I have a great function in VBA which returns the network login name. I use this simply to add the user name to emails. Unfortunately the name is returned in lower case, which doesn't look as good as it could. Is there a way to ensure the name returned is correctly capitalised. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capitalise
Mike
That gives me RICHARD rather than Richard, I should have given an example sorry. "Mike H" wrote: Richard, Try this line fOSUserName = UCase(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Hi I have a great function in VBA which returns the network login name. I use this simply to add the user name to emails. Unfortunately the name is returned in lower case, which doesn't look as good as it could. Is there a way to ensure the name returned is correctly capitalised. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (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 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capitalise
Richard,
Try this fOSUserName = WorksheetFunction.Proper(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Mike That gives me RICHARD rather than Richard, I should have given an example sorry. "Mike H" wrote: Richard, Try this line fOSUserName = UCase(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Hi I have a great function in VBA which returns the network login name. I use this simply to add the user name to emails. Unfortunately the name is returned in lower case, which doesn't look as good as it could. Is there a way to ensure the name returned is correctly capitalised. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (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 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capitalise
Mike
Thats it thanks. I find it infuriating that what should be so obvious takes me so long and then I have to ask dumb questions. Thanks again Richard "Mike H" wrote: Richard, Try this fOSUserName = WorksheetFunction.Proper(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Mike That gives me RICHARD rather than Richard, I should have given an example sorry. "Mike H" wrote: Richard, Try this line fOSUserName = UCase(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Hi I have a great function in VBA which returns the network login name. I use this simply to add the user name to emails. Unfortunately the name is returned in lower case, which doesn't look as good as it could. Is there a way to ensure the name returned is correctly capitalised. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (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 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capitalise
Glad I could help
"Richard" wrote: Mike Thats it thanks. I find it infuriating that what should be so obvious takes me so long and then I have to ask dumb questions. Thanks again Richard "Mike H" wrote: Richard, Try this fOSUserName = WorksheetFunction.Proper(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Mike That gives me RICHARD rather than Richard, I should have given an example sorry. "Mike H" wrote: Richard, Try this line fOSUserName = UCase(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Hi I have a great function in VBA which returns the network login name. I use this simply to add the user name to emails. Unfortunately the name is returned in lower case, which doesn't look as good as it could. Is there a way to ensure the name returned is correctly capitalised. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (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 |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Capitalise
One more...In vbscript use the String Conversion function .For example
=STRCONV("RICHARD",vbProperCase) If this post helps click Yes --------------- Jacob Skaria "Mike H" wrote: Glad I could help "Richard" wrote: Mike Thats it thanks. I find it infuriating that what should be so obvious takes me so long and then I have to ask dumb questions. Thanks again Richard "Mike H" wrote: Richard, Try this fOSUserName = WorksheetFunction.Proper(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Mike That gives me RICHARD rather than Richard, I should have given an example sorry. "Mike H" wrote: Richard, Try this line fOSUserName = UCase(Left$(strUserName, lngLen - 1)) Mike "Richard" wrote: Hi I have a great function in VBA which returns the network login name. I use this simply to add the user name to emails. Unfortunately the name is returned in lower case, which doesn't look as good as it could. Is there a way to ensure the name returned is correctly capitalised. Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _ "GetUserNameA" (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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Capitalise first word in a cell | Excel Discussion (Misc queries) | |||
CAPITALISE | Excel Discussion (Misc queries) | |||
CAPITALISE GLOBALLY | Excel Discussion (Misc queries) | |||
Trying to Capitalise on Input to Cells | Excel Worksheet Functions | |||
Capitalise Letters | Excel Programming |