Results 1 to 4 of 4

Thread: VBA for Word - Noob needs some assistance.

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2005
    Location
    Dallas, TX
    Posts
    3

    Question VBA for Word - Noob needs some assistance.

    I have been punted the task of creating a macro for distribution that will append <Signature:USERNAME> to a word document.

    USERNAME = Current logged on user.

    I have no clue what variable to use for enumerating the current logged on user in VBA.

    I have been playing with various things, but due to my lack of experience with VB I have had no success.

    Sub NewMacros()

    Selection.TypeText Text:="<Signature:Environment.UserName>"

    End Sub


    I am a little familiar with WSH, but have never done anything with VBA, so any assistance would be appreciated.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: VBA for Word - Noob needs some assistance.

    Not sure if word has this, but Excel has Application.UserName, which returns the name of the person using Excel, or whoever it's registered to if they don't have to log in somehow.
    To get the user name of the person logged on to the computer, use the GetUserName API. This will work in any version of VB up to and possibly including .Net, although there you can use Environment.UserName more easily. This will be their logon name, so if they log on as "smith.j" that's what you'll get.
    Tengo mas preguntas que contestas

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2005
    Location
    Dallas, TX
    Posts
    3

    Re: VBA for Word - Noob needs some assistance.

    Thanks. I will check this out.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2005
    Location
    Dallas, TX
    Posts
    3

    Resolved Re: Appending user name Text string in Word Document

    Thanks for any assistance on this. Here is the functioning code for the future. This code will append the following text to any word document.

    <SIGNATURE:DOMAIN USERNAME>

    This code is intended to append a signature to a word document in conjunction with RIghtFax.


    Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    Sub main()

    Dim str As String
    Dim result As Long

    result = 0
    str = Space(1000)

    result = GetUserName(str, Len(str))
    result = Len(Trim(str))
    str = Left(str, Len(Trim(str)) - 1)
    'ActiveDocument.Select - Uncomment this only to replace all text in document
    Selection.Text = "<SIGNATURE:" + str + ">"

    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width