Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Document Properties (2003)

    I have a large number of documents (over 600) that need to have the title changed in it's properties. I'm understanding now that the title it's picking up is the first line in the document, which in this case isn't the document's title. Is there anyway of changing some sort of setting to make it read (in my case) the third line in the document as the title? I'm just trying to save a lot of tedious work!

    Thanks for any suggestions.

    Deb

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Document Properties (2003)

    Just to make sure: do you mean the third line or the third paragraph (they might coincide, but not necessarily so)?

  3. #3
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Document Properties (2003)

    Thanks Hans.

    The title is the third typed line in each document. Quick example: First Line reads "Administrative Manual", second line reads "1-10", third line reads "Memberships". Currently, all document titles are named Administrative Manual. In my example, it should be named "Memberships". I've started manually changing them over, but I have the feeling this may take a month of Sundays!

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Document Properties (2003)

    Try the following:
    - Create a new folder, name it Test or something like that.
    - Copy the documents you want to change into this folder (don't move them, you may want the originals if something goes wrong).
    - Make sure no other documents are stored in the folder.
    - Create a new word document (don't store it in the new folder)
    - Activate the Visual Basic Editor (Alt+F11)
    - Create a new module (Insert | Module)
    - Copy the following macro into the module:
    <code>
    Sub Retitle()
    ' Path - make sure it ends in a backslash
    Const strPath = "C:WordTest"
    ' Variables
    Dim strFile As String
    Dim doc As Document
    Dim strTitle As String

    On Error GoTo ErrHandler

    ' Turn off screen updating (doesn't help much)
    Application.ScreenUpdating = False
    ' First file name
    strFile = Dir(strPath & "*.doc")
    ' Loop through files
    Do While Not strFile = ""
    ' Open document
    Set doc = Documents.Open _
    (FileName:=strPath & strFile, AddToRecentFiles:=False)
    ' Get 3rd paragraph
    strTitle = doc.Paragraphs(3).Range.Text
    strTitle = Left(strTitle, Len(strTitle) - 1)
    ' Set title
    doc.BuiltInDocumentProperties(wdPropertyTitle) = strTitle
    ' Close and save
    doc.Close SaveChanges:=wdSaveChanges
    ' Get next document name
    strFile = Dir
    Loop

    ExitHandler:
    ' Clean up
    Set doc = Nothing
    ' Turn on screen updating
    Application.ScreenUpdating = True
    Exit Sub

    ErrHandler:
    ' Display error message
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub
    </code>
    - Modify the constant strPath so that it contains the full path to your folder.
    - Make sure that the path ends in a backslash .
    - You can run the macro in two ways:
    - Click in it in the Visual Basic Editor and press F5.
    - Switch back to Word, press Alt+F8, select Retitle and click Run.

  5. #5
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Document Properties (2003)

    Thank you so much Hans...I'll test when I have a free moment. I really appreciate this!

  6. #6
    2 Star Lounger
    Join Date
    Dec 2004
    Location
    Stoney Creek, Ontario
    Posts
    196
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Document Properties (2003)

    Hans, I wanted to extend my thanks again for this piece of code. It worked beautifully! You have saved me a ton of time. I also want to say that I really appreciate the comments within the code...this is very helpful in understanding what it does!

    Deb

Posting Permissions

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