#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 709
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default 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
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
Capitalise first word in a cell alba146 Excel Discussion (Misc queries) 2 August 4th 09 11:28 AM
CAPITALISE Prasad Gopinath Excel Discussion (Misc queries) 8 March 1st 08 03:36 PM
CAPITALISE GLOBALLY Prasad Gopinath Excel Discussion (Misc queries) 5 February 10th 08 09:08 PM
Trying to Capitalise on Input to Cells John Excel Worksheet Functions 3 June 23rd 06 03:18 PM
Capitalise Letters John[_78_] Excel Programming 3 April 30th 04 12:00 PM


All times are GMT +1. The time now is 07:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"