Batch renaming Titles, Author, etc (meta tags)

T

todd

I would like to batch process all of the "Summary" meta tag information on
many word documents. I'm uploading many documents into Sharepoint and over
the years, these documents have never had the "title" and "author" updated.

What VBA would I need in order to open a word document, copy the file name
as a parameter, set the "Title" in the Properties box to the file name that
was copied, change the "Author" to Joe Schmoe and set the "Company" to just
read "company"?

If I were to use the same VBA in Excel, what would I need to change?

Thank you in advance.
 
D

Doug Robbins - Word MVP

The following code will display a dialog box allowing you to select the
folder that contains the files that you want to process and then will make
the necessary changes to each document in that folder:

Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim fd As FileDialog

Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Select the folder containing the files."
If .Show = -1 Then
PathToUse = .SelectedItems(1) & "\"
Else
Exit Sub
End If
End With
Set fd = Nothing
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
'Set the directory and type of file to batch process
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
'Open document
Set myDoc = Documents.Open(PathToUse & myFile)
With myDoc
.BuiltInDocumentProperties(wdPropertyTitle) = .Name
.BuiltInDocumentProperties(wdPropertyAuthor) = "Joe Schmoe"
.BuiltInDocumentProperties(wdPropertyCompany) = "company"
.Close SaveChanges:=wdSaveChanges
End With
'Next file in folder
myFile = Dir$()
Wend


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
T

todd

Awesome - that worked!

One question, is it possible to set the title property so that it does not
include the ".doc" part of the file name?
 
P

Peter Jamieson

..BuiltInDocumentProperties(wdPropertyTitle) = _
Left(.Name, Len(.Name)-InStr(1, StrReverse(.Name), "."))

should get rid of anything from the last "." onwards.

Peter Jamieson

http://tips.pjmsn.me.uk
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top