• Document Properties (2003)

    Author
    Topic
    #429494

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1000411

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

      • #1000413

        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!

        • #1000414

          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:

          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

          – 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.

          • #1000419

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

            • #1000534

              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

    Viewing 0 reply threads
    Reply To: Document Properties (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: