PC Review


Reply
 
 
Richard
Guest
Posts: n/a
 
      7th Apr 2009
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 With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      7th Apr 2009
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 With Quote
 
Richard
Guest
Posts: n/a
 
      7th Apr 2009
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 With Quote
 
Mike H
Guest
Posts: n/a
 
      7th Apr 2009
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 With Quote
 
Richard
Guest
Posts: n/a
 
      7th Apr 2009
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 With Quote
 
Mike H
Guest
Posts: n/a
 
      7th Apr 2009
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 With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      7th Apr 2009
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Capitalise on Input Q Seanie Microsoft Excel Programming 3 5th Dec 2010 04:26 PM
how to capitalise I Davy858 Microsoft Word Document Management 2 26th Jul 2009 10:33 PM
CAPITALISE Prasad Gopinath Microsoft Excel Misc 6 29th Feb 2008 08:41 PM
CAPITALISE GLOBALLY Prasad Gopinath Microsoft Excel Misc 5 10th Feb 2008 09:08 PM
Re: CAPITALISE LETTERS John Smith Microsoft Access Form Coding 1 30th Jul 2003 10:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:48 PM.