View Full Version : Adding to generic Document properties

04-03-2007, 06:48 AM
Hi all

I've been traversing the forums and I haven't found anything about being able to iterate through a list a files and adding a piece of text to the 'Comments' or 'Title' properties. These are bits of metadata that seem to be common amongst all file types in windows. Any help would be very much appreciated.


04-03-2007, 07:48 AM
Can't remember who contributed this but it seems to do what your asking:
Option Explicit
Private Sub CommandButton1_Click()
End Sub
Private Sub UserForm_Initialize()
txtTitle = ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle)
txtSubject = ActiveDocument.BuiltInDocumentProperties(wdPropertySubject)
txtCategory = ActiveDocument.BuiltInDocumentProperties(wdPropertyCategory)
End Sub

Sub BatchChangeCompanyWordProperties()
'A VBA macro to bulk change the properties of word documents within a folder

Application.ScreenUpdating = False
Dim i As Long
With Application.FileSearch
.LookIn = "F:\Temp\test\New Folder"
.SearchSubFolders = False
.FileType = msoFileTypeWordDocuments
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Documents.Open .FoundFiles(i)
'Description Properties
If txtTitle <> "" Then ActiveDocument.BuiltInDocumentProperties(wdPropertyTitle) _
= txtTitle.Text
If txtSubject <> "" Then ActiveDocument.BuiltInDocumentProperties(wdPropertySubject) _
= txtSubject.Text
If txtCategory <> "" Then ActiveDocument.BuiltInDocumentProperties(wdPropertyCategory) _
= txtCategory.Text

ActiveDocument.Close wdSaveChanges
Next i
MsgBox "There were no files found."
End If
End With
Application.ScreenUpdating = True
End Sub

Edit: code above is for a userform....file attached.

04-04-2007, 10:49 AM
Hi Lucas

Thanks for that, very helpful. Would you have any ideas as to how this could be done for non office docs/files?


04-04-2007, 11:53 AM
I'm afraid not....maybe someone will drop by with some ideas.