Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    May 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how do I create a macro in word the uses the username from windows

    i want the username to be taken from windows %username% this way a user can only use their signature and not see everyone's signature


    my macro right now is

    Sub user_signature()
    '

    '
    Selection.InlineShapes.AddPicture FileName:= _
    "h:\templates\signatures\username.tif", LinkToFile:=False, SaveWithDocument:= _
    True
    CommandBars("Drawing").Visible = True
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    End Sub

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='destro613' post='777242' date='27-May-2009 18:41']how do I create a macro in word the uses the username from windows[/quote]
    Try
    Code:
    strUsername = Environ("username")
    and
    Code:
    Selection.InlineShapes.AddPicture _
    	FileName:="h:\templates\signatures\" & strUsername & ".tif", _
    	LinkToFile:=False, _
    	SaveWithDocument:=True
    If that doesn't work, Word VBA has access to the full Windows API, so you could look up an API method. You also could use the Windows Script Host's WshNetwork object, which has a UserName property. As between these, the API method might be harder to learn, but it probably will have better performance and be more reliably available (the WSH sometimes is blocked or disabled due to abuse by malware in the past).

Posting Permissions

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