Solved

Custom field in word 2010 template - how to?

Posted on 2014-09-22
5
344 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now