NT Username auto fill-in

J

Jon S.

I need to know how I can have a users NT domain username
autofilled into a field such as form field or another
specific location on a word doc in Office XP. I am presume
this would need a macro and if anyone has a working code
example I would love to see it. Also, if there is another
method, that would also be excellent.

-Regards
Jon
 
J

Jay Freedman

Hi Jon,

Yes, it requires a macro.

First, get the username into a string variable this way:

Dim strUserNm As String
strUserNm = Environ("Username")

Then insert that string into the document by your method of choice.
For example, if the document is a protected form with a text form
field named UserNm, the code would be

ActiveDocument.FormFields("UserNm").Result = strUserNm

Instead, the document (or the template on which it's based) could have
a bookmark named UserNm, and you could use code similar to that at
http://word.mvps.org/FAQs/MacrosVBA/InsertingTextAtBookmark.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top