Solved

Custom field in word 2010 template - how to?

Posted on 2014-09-22
5
348 Views
Last Modified: 2014-09-23
In a small network with a handful of users but some sharing of PC's there is now a requirement to show the logged in user as the creator of a word document based on a centrally located template.
So it would be nice to have a field in the template (eg. in the footer) which will get the login name of the user when the template is used to create a new document.  There is a tiny problem, the login names are in the format of John.Smith or Harry.Brown so the '.' needs to also be replaced with a space.

I can insert a field, what do I need to do to get the login name AND then replace all instances of '.' with a space in that retrieved name to put into that field at the time of document creation.  (I don't want this information changing should another user edit the document at a later time.

(In theory one could go to each PC, login as each potential user and change a setting in the options for word - but that is a horrible looking hack and waste of time and resources)
0
Comment
Question by:AndyAinscow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 24

Assisted Solution

by:Phillip Burton
Phillip Burton earned 150 total points
ID: 40336444
I don't believe you can directly. You can do some wonderful tricks with fields, but they seem to be mostly used with numbers - see http://www.techrepublic.com/blog/10-things/10-power-tricks-for-using-word-field-switches/ as an example.

What you can do instead is to change what the computer thinks the original author is at the time of document creation.

You would create your field in Normal.dot relating to the Author (Insert - Quick Parts - Fields - Author - OK), and then have this code in Normal.dot (press Alt+F11, and go to Normal - Microsoft Word Objects - This Document):

Private Sub Document_New()
Me.BuiltInDocumentProperties("Author") = Replace(Me.BuiltInDocumentProperties("Author"), ".", " ")
End Sub

Open in new window


You would then need a certificate to verify your identity on other computers - you can use SelfCert.exe if you haven't go one - and then associate that certificate with your code (Tools - Digital Certificate).

It all depends on whether you are used to using VBA or not as to whether I would recommend going down that route.
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 350 total points
ID: 40336546
You can use this function to find the log-in name,
Function GetLoginName() As String
    Dim i As Integer
    Dim strParts() As String
    
    i = 1
    Do Until Environ(i) = Empty
        strParts = Split(Environ(i), "=")
        If StrComp(strParts(0), "USERNAME", vbTextCompare) = 0 Then
            GetLoginName = Replace(strParts(1), ".", " ")
        End If
        i = i + 1
    Loop
End Function

Open in new window


which you can use to set the Author property.
Private Sub Document_New()
      ActiveDocument.BuiltInDocumentProperties("Author") = GetLoginName()
End Sub

Open in new window

0
 
LVL 44

Author Comment

by:AndyAinscow
ID: 40338434
Thanks for the responses.  Hmm, not as trivial as I expected.  I'll see if I can get it tested today.
0
 
LVL 44

Author Comment

by:AndyAinscow
ID: 40338580
I've got it to work here on a single PC, it has been passed on for testing (by my tame tester) in situ in the real life network.  I'll close this / ask for further advice when I get a response back.


ps.  Please cast a glance at:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_28523653.html
It is a follow up to this question.
0
 
LVL 44

Author Closing Comment

by:AndyAinscow
ID: 40338749
Great work guys, your help is appreciated.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question