Solved

Custom field in word 2010 template - how to?

Posted on 2014-09-22
5
342 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Great work guys, your help is appreciated.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
easy to edit manual application 2 61
Renumber Word data 5 46
Word - Access 6 43
MS Word Formatting 3 25
There is a feature provided by MS Word that lets you create an Table of Contents for your Word document automatically. To use this feature for other documents there are two steps involved,   1.  Prepare your document for a table of contents (he…
Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
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:

744 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