Set a default value for Manager in Microsoft Word document properties field

Set a default value for Manager in Microsoft Word document properties field

Is it possible to automatically set the 'Manager' field in the Microsoft Word document properties section?

enter image description here

We have the manager information stored in our Active Directory and it would be great if this field would automatically populate with this information.

I am using Microsoft Office 365.

答案1

Change this in your Normal.dotm template or the template you are using to create new documents.

That is the simplest method. Here is a macro that will do this for the normal template. You can comment out the line with the InputBox if you want a fixed name, then remove the apostrophe in front of the one that has a fixed name and change "Manager Name" to what you want (keeping the quotation marks). As written, it will ask for the name each time you run the macro.

Note the Normal template should not be shared and you should not be overwriting a user's template with one that you have fixed. The macro should be run on each computer.

Sub ManagerPropertyNormalSet()
    ' Charles Kenyon 2022-07-18
    ' https://superuser.com/questions/1732280/set-a-default-value-for-manager-in-microsoft-word-document-properties-field
    Application.ScreenUpdating = False
    Application.NormalTemplate.OpenAsDocument
    Dim strManager As String
    ' Let strManager = "Manager Name"
    Let strManager = InputBox(Prompt:="What name do you want in the Manager Property?", _
        Title:="Set Manager Property in Normal Template")
    ActiveDocument.BuiltInDocumentProperties("Manager") = strManager
    ActiveDocument.Saved = False
    ActiveDocument.Close SaveChanges:=True
    Application.ScreenUpdating = False
    MsgBox "The Normal template now has the Manager property set to be " & _
        strManager, Buttons:=vbInformation, title:="All done."
End Sub

For a template other than the Normal template, simply open the template for editing and change the property.

See Instructions for Installing Macros from Forums or Websites by Graham Mayor, MVP

相关内容