Consulting

Results 1 to 14 of 14

Thread: Retrieving initials

  1. #1
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    144
    Location

    Retrieving initials

    Hi all,

    I hope this is a little one ... I have a macro retrieving and showing the User Name and the actual date in a comment field. The keyline of the code is:

    shp.TextFrame.TextRange.Characters.Text = Environ("UserName") & " " & DataValue(Now) & ": "
    Now I would like to change it a bit, as the User Name sometimes is quite long. I would like to replace it by the initials. But it seems, initials are not part of the information I can retrieve by using "Environ". Any idea how to solve this in a way as simple as the one I got?

    Thanks in advance!
    RG

  2. #2
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    5,993
    Location
    Maybe

    Option Explicit
    Sub Initials()
        Dim i As Long
        Dim s As String
        Dim v As Variant
        
        v = Split(UCase(Environ("USERNAME")), " ")
        
        For i = LBound(v) To UBound(v)
            s = s & Left(v(i), 1)
        Next i
        
        MsgBox s
        
    End Sub
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    144
    Location
    Thanks a lot, Paul, this works well and is easy to embed into my code. So I assume, there is no way to read out the initials directly, what I hoped for, as they are part of the general menu in the PowerPoint Options.

  4. #4
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    5,993
    Location
    I couldn't find the initials

    However, if you have a presentation open, you might consider using the build in doc props instead of ENVIRON and then generate the initials


    Sub test2()
    
    
        MsgBox ActivePresentation.BuiltInDocumentProperties("Author")
        
    End Sub
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    144
    Location
    Thank you, Paul, this works as well. What is the advantage compared to the solution with ENVIRON?

  6. #6
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,700
    Location
    You can read the initials from the registry (Not always the same answer as generating from the author) Author and UserName are not necessarily the same anyway.

    Function RegKeyRead(i_RegKey As String) As String
    Dim myWS As Object
      On Error Resume Next
      Set myWS = CreateObject("WScript.Shell")
      RegKeyRead = myWS.RegRead(i_RegKey)
    End Function
    
    
    Sub chexInitials()
    MsgBox RegKeyRead("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\UserInitials")
    End Sub
    
    
    Sub chexname()
    MsgBox RegKeyRead("HKEY_CURRENT_USER\Software\Microsoft\Office\Common\UserInfo\UserName")
    End Sub
    Last edited by John Wilson; 08-07-2018 at 02:36 AM.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  7. #7
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    5,993
    Location
    Quote Originally Posted by RandomGerman View Post
    Thank you, Paul, this works as well. What is the advantage compared to the solution with ENVIRON?
    Depends on what you want

    1. The person logged on, or

    2. The creator of the presentation
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    144
    Location
    @Paul: Okay, got it. I'm looking for the person logged on. So I have to prefer ENVIRON - or John's solution.

    @John: Thank you very much. This seems to be as close as possible to what I was looking for.

    Are there any advantages on Paul's first or John's solution, or is it just personal taste to solve it with or without the "external" function?

    Thank you both so much!

  9. #9
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    5,993
    Location
    Since you can put anything in "Initials" even if they don't have anything to do with the User name, John's will retreive them (XYZ in screen shot)

    Personally I'd test the length of EVIRON ("UserName") and then if it was too long, use the Split() technique from post 2 to 'shrink' it


    So "Some User At Work" would shrink to "S. U. A. Work"

    Capture.JPG
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  10. #10
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    144
    Location
    Ah, I see. While ENVIRON is "incorruptible" using the Log-on name, John's solution is dependent on if the user knows, that he could change initials in the Office options. Very interesting.

    Thank you once more!

  11. #11
    VBAX Master
    Joined
    Feb 2007
    Posts
    1,700
    Location
    While it's hard to change Environ(USERNAME) it can be set to anything originally (Mine is johnw which doesn't split to initials.) Depends whether you need the computer logon person or the PowerPoint Author which you use.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  12. #12
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    144
    Location
    My UserName is only one word, too, but as I never cared about changing my initials in Office, it was only one letter there, too. ;-)

    I'm definitely not looking for the author of a presentation but for the person actually working on it. My macro is meant for team communication, that's why I want to add date and initials automatically to the shapes used for this communication. Works fantastic thanks to the help of both of you, I just have to make the decision between the two options, that's why I asked for advantages.

  13. #13
    VBAX Wizard
    Joined
    Apr 2007
    Posts
    5,993
    Location
    From the #1 --

    Now I would like to change it a bit, as the User Name sometimes is quite long. I would like to replace it by the initials. But it seems, initials are not part of the information I can retrieve by using "Environ". Any idea how to solve this in a way as simple as the one I got?
    How long is 'quite long'?

    The USERNAME is probably the most unambiguous, and if the IT people use real name, it might be the best even if long
    Paul

    ------------------------------------------------------------------------------------------------------------------------
    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s)
    (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  14. #14
    VBAX Contributor
    Joined
    Apr 2015
    Location
    Germany
    Posts
    144
    Location
    Oh, that's more a philosophical question, maybe. I guess, someone discussing with a person called Abercrombie Jonathan Yellowliver might be less happy with the USERNAME used for the function than someone discussing with Joe Hart. ;-)

    I will discuss it with the affected team members, I guess that makes most sense. And it is great to have two options.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •