Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Macro needed to point to a folder full of docs and apply template styles!

    Hello,

    I have a folder full of MS Word 2010 documents that I would like to change.

    I have a source MS Word template with styles that I would like to apply to all of the documents
    in my target folder.

    Is it possible to have a macro:

    1. Ask for the folder in question.
    2. Find each MS Word document (.DOCX).
    3. Remove the existing styles in the document.
    4. Apply the new (desired) styles from a template (.DOTX) file.
    5. Save and close the file.
    6. Goto step 2.

    Thanks for any suggestions on how to make this work.
    Once again, I am using MS Word 2010.

    Regards,

    -J

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Can you explain what you mean by steps 3 and 4?

    Is this remove all styles from the document? Is it change all content to Normal style? Word only allows you to remove custom-built styles. It also allows you to hide the built-in styles.

    When you apply the new template styles, do you mean refresh the style definitions or apply the right style to the right paragraph? If you are actually applying planning to apply the styles, how do you do this after removing all style information in step 3?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  3. #3
    3 Star Lounger
    Join Date
    Jan 2007
    Location
    Massachusetts, USA
    Posts
    272
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hi Andrew,

    Thanks for the reply.
    I am trying to create a macro that will allow me to:

    1. Point to a "C" drive folder (e.g. Test1) full of documents.
    2. Delete all the existing styles (custom styles I guess) in a document.
    3. Open a template in the same folder.
    4. Apply ALL STYLES from that template to the document that just had its styles removed.
    5. Save the document, close it and loop over to the next document and repeat process.

    Here is a macro I recorded. It does not have loop functionality and I am not sure how ideal it is, but it gives you an idea.

    Thanks for any assistance you can provide. Here is that sample macro:


    Code:
    Sub ApplyStyles()
    '
    ' ApplyStyles Macro
    '
    '
        ChangeFileOpenDirectory "C:\Temp1\"
        Documents.Open FileName:="Test.doc", _
            ConfirmConversions:=False, ReadOnly:=False, AddToRecentFiles:=False, _
            PasswordDocument:="", PasswordTemplate:="", Revert:=False, _
            WritePasswordDocument:="", WritePasswordTemplate:="", Format:= _
            wdOpenFormatAuto, XMLTransform:=""
        Application.OrganizerDelete Source:= _
            "C:\Temp1\Test.doc", Name:="Footer", _
            Object:=wdOrganizerObjectStyles
        Application.OrganizerDelete Source:= _
            "C:\Temp1\Test.doc", Name:="Header", _
            Object:=wdOrganizerObjectStyles
        Application.OrganizerDelete Source:= _
            "C:\Temp1\Test.doc", Name:="page_header", _
             Object:=wdOrganizerObjectStyles
        Application.OrganizerDelete Source:= _
            "C:\Temp1\Test.doc", Name:= _
            "Para_Title_Ruled", Object:=wdOrganizerObjectStyles
        Application.OrganizerDelete Source:= _
            "C:\Temp1\Test.doc", Name:= _
            "Paragraph text", Object:=wdOrganizerObjectStyles
        Application.OrganizerDelete Source:= _
            "C:\Temp1\Test.doc", Name:= _
            "Paragraph_Title", Object:=wdOrganizerObjectStyles
        Application.OrganizerDelete Source:= _
            "C:\Temp1\Test.doc", Name:="TM TITLE", _
             Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Normal,Normal_Para", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Balloon Text", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Paragraph text", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="blank_page", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="bold", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Callouts_Style", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Caption", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Caption1", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Computer Text", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Computer Text Bold", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Default Paragraph Font", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Fig_Title", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Figure", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Figure legend", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Footer", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Footnotes", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Header", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Heading 1,Chapter", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Heading 2,Work_Package", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Heading 3,Heading 3_style", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Index Heading", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Index_list", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Sub_Para_Title", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Initial Setup Subtitle", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Initial Setup text", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Paragraph_Title", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="initial setup title", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="List_header", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="No List", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="page_header", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="page_footer", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Para_Title_Ruled", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Paragraph text bulleted", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Procedure bullet", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Procedure bullet 2", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Procedure Sub-Title", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Procedure Title", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Procedures", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Procedures_style", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="RPSTL_COL_HD", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="RPSTL_text", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Table Normal", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Table Grid,Table_Grid", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Table_footnote", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="table_step 1", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="table_step a", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="table_text", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="table_step_(1)", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="table_step_(a)", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="table_text_centered", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="table_text_indented", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Table_Title", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Tbl_Column_head", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="TBL_Column_head_left", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="Title Block Page", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="TOC_INDEX_(etc)_Header", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="WCN_Text", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="WCN_centered", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="WCN_Head", Object:=wdOrganizerObjectStyles
        Application.OrganizerCopy Source:="C:\Temp1\Template1.docx" _
            , Destination:="C:\Temp1\Test.doc", Name _
            :="TM TITLE", Object:=wdOrganizerObjectStyles
        ActiveDocument.Save
        ActiveDocument.Close
    End Sub
    Last edited by macropod; 2012-02-24 at 01:48. Reason: Added code tags

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    For a fully-fledged implementation, see posts #33 & later: http://www.msofficeforums.com/vba/10...nizercopy.html
    Take particular note of the difficulties involving many built-in styles, starting at post #13.

    PS: When posting code, please use code tags.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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