Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In a template document I want to create a macro that when the template is opened and a new document is pulled up, the "author" name will automatically insert into the footer. Is this possible? I don't know how to write macro code and all the instructions I've found is very confusing to me. I used to be able to create auto-execute macros in very old version of Word but the 2010 is very confusing.

share|improve this question
add comment

4 Answers

up vote 0 down vote accepted

Hit Alt + F11 and on the left you'll see your project and Microsoft Word Objects

Put the following code into ThisDocument in the visual basic editor

Private Sub Document_New()
   With ActiveDocument.Sections(1)
    .Footers(wdHeaderFooterPrimary).Range.Text = ActiveDocument.BuiltInDocumentProperties("Author") & "      " & Now
   End With
End Sub

Close VB Editor and save as Word Macro-Enabled Template

share|improve this answer
    
I will try this and see if it works. Thanks! –  user242332 Jul 31 '13 at 20:37
    
Sorry, but it didn't work :( –  user242332 Jul 31 '13 at 20:44
    
Didn't work for you or didn't work for someone else? Are macros enabled? –  Raystafarian Jul 31 '13 at 20:53
    
when I open the template to the new document there is a message across the top that says macrose disabled, I click on it the enable, but the macro didn't run. –  user242332 Jul 31 '13 at 20:56
    
@user242332 changed it to document_new now it works. Sorry –  Raystafarian Jul 31 '13 at 21:49
show 4 more comments

A macro is not necessary to automatically insert the author's name. It can be done using just a template and the Author field. To do this:

  • Open a new document.
  • Add a footer to the document (fastest way is to double click just above the bottom of the page)
  • In the Header & Footer Tools ribbon, click Quick Parts then Document Property and Author. enter image description here
  • Save the document as a Template (.dotx). Do not save it as a regular document (.docx).

To create a new document and have it automatically grab the author's name, just double click the template file or, from the New document window, select New from existing and browse to it. The new document will open as a DOCX file, not the DOTX template. The original author's name will be grabbed by the document and it can be saved as a normal document. The name should not change unless someone opens the footer and explicitly updates the field.

Note: To edit the template itself after closing, hold down Shift while right clicking the file, then select Edit. Opening it otherwise will turn it into a standard document, not a template.

2nd Note: You can add Document Property fields to a regular DOCX document, but it will usually re-update the author each time the document is opened and saved (i.e., grabbing the name of whoever opens it, not the original author).

share|improve this answer
    
Thanks for this information, but this is not what I am attempting to do. Example: we have a template that different people may open and each time we open this template we have to remember to go into the footer and change our name as the author of the document. Sometimes, the use forgets. Creating a macro that would automatically insert the Author's name of the person that is using the template to create a new document e.g. a pre-designed form, is what I am trying to do here. –  user242332 Jul 31 '13 at 23:14
    
@user242332, A field in the footer will update automatically when the document is opened. This answer and the accepted answer using the macro do the exact same thing, the only difference is that the one with the macro is a lot more work and not as concise. BTW perhaps you are looking for the UserName field which inserts the name of the computer (i.e the name found under Control Panel -> System). –  Adam Aug 1 '13 at 11:47
add comment

If you add the Developer tab (Go to File|Options|Customize Ribbon then under Customize the Ribbon and under Main Tabs, select the Developer check box), you can use the macro recorder to do what you want.

  1. In the Code section, select Record Macro
  2. Choose whether you want a button or keyboard shortcut to trigger it and where to save the macro it creates
  3. Record you macro - something like this should do it:

    • Insert|Footer|Edit Footer
    • Insert|Quick Parts|Document Property|Author
  4. Then press Stop Recording

That should generate you a macro to do roughly what you want. You'll need to play around a bit if you want to specify where in the footer you want the Author field placed.

share|improve this answer
    
I did this and it wouldn't do it as a Automatic Macro when the template document is opened to a new document. –  user242332 Jul 31 '13 at 21:00
    
In order to run automatically, the code you recorded needs to be added to the Private Sub Document_Open() section of your code. It cannot be left in the Sub created automatically when you did the recording. It also must be saved as a Macro-enabled document (DOCM). –  techturtle Jul 31 '13 at 21:20
add comment

user242332's advice above regarding the UserName field is the way to go. I've been building a lot of .dotx files lately and have been experimenting with the use of field codes and they are awesome. To set up the UserName field in the footer go to: http://office.microsoft.com/en-us/word-help/insert-and-format-field-codes-in-word-2007-HA010338798.aspx

Essentially, you just need to place your cursor where you want the author's name in the footer, go to the Insert tab and select Quick Parts and then go to the fields section.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.