by Allen Wyatt
(last updated June 30, 2018)
Rachel has several hundred documents in which she needs to change the title property. (This is the title property maintained with the other document properties.) She wonders if there is a way to easily make this change in such a large number of documents.
Word doesn't have a built-in way to affect a large number of documents at the same time, but you can create a macro to do the work for you. The important thing to remember is that you want to be able to access the built-in document Title property, and you do that in VBA by fiddling with the BuiltInDocumentProperties collection. For instance, you can change the Title property in VBA in this manner:
ActiveDocument.BuiltInDocumentProperties("Title") = "xyz"
To make your macro effective for a large number of documents, all you'd need to do is to determine the names of the documents you want to affect, load each document in turn, change the Title property, and then save the document. The following macro accomplishes this set of tasks:
Sub ChangeTitles() Dim Directory As String Dim FType As String Dim FName As String Dim sTitle As String Dim sFiles(250) As String Dim iFiles As Integer Dim J As Integer Directory = Environ("USERPROFILE") & "\Desktop\temp\" FType = "*.docx" sTitle = "My New Doc Title" ' Get names of documents iFiles = 0 FName = Dir(Directory & FType) While FName <> "" iFiles = iFiles + 1 sFiles(iFiles) = FName FName = Dir Wend ' Process files For J = 1 To iFiles Documents.Open FileName:=Directory & sFiles(J) ActiveDocument.BuiltInDocumentProperties("Title") = sTitle ActiveDocument.Close wdSaveChanges Next J End Sub
Note that near the beginning of the macro the Directory variable is set equal to the full path to the "temp" folder on the desktop. You should make sure that Directory is set to the full path to wherever you have the documents you want to change. Note, as well, that the path ends with a backslash—this is very important.
The other variable you'll want to change is the new title that you store in the sTitle variable. Every document in the Directory folder will have its Title property changed to whatever is stored in the sTitle variable.
The first part of the macro steps through all the files in the target directory and grabs the name of any DOCX file there. These are stored in the sFiles array. Once this is complete, then the array is stepped through and used as a guide for the files to be opened and changed.
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13543) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 365.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
If you need to refer to the same information over and over in a document, you may be interested in using custom document ...Discover More
Word maintains, in a document's properties, several dates such as the date the document was created and last accessed. ...Discover More
Word allows you to keep track of any number of custom properties about a document. Here's how to create those properties ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.