Consulting

Results 1 to 4 of 4

Thread: Adding to generic Document properties

  1. #1

    Adding to generic Document properties

    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.

    cheers
    md82

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Can't remember who contributed this but it seems to do what your asking:
    [vba]Option Explicit
    Private Sub CommandButton1_Click()
    BatchChangeCompanyWordProperties
    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
    Else
    MsgBox "There were no files found."
    End If
    End With
    Application.ScreenUpdating = True
    End Sub
    [/vba]
    Edit: code above is for a userform....file attached.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    Hi Lucas

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

    thanks
    m

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I'm afraid not....maybe someone will drop by with some ideas.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •