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

    I have a folder full of MS Word documents and I need to change the color for Heading 1 in every chapter and in every document.

    The client is using a specific color, so I need to use the Red Green Blue Color Model in MS Word to choose specific colors,
    using the RGB model (e.g. Red:62, Green:102, Blue:72).

    Is there a way that this can be done through a macro for: Heading 1, Heading 2, as well as the shading in a table column head?

    I am using MS Word 2010 (Windows 7 64 bit Laptop).

    Thanks in advance.

    -J

  2. #2
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Assuming your documents are all based on the same template, you could do this easily by updating the template style for Heading 1.

    Then you need to add a macro to the template like this. Whilst this doesn't actually open each document and make the change immediately, it does set the framework so that when you do open any of the documents then the styles will be refreshed from the template.
    Code:
    Sub AutoOpen()
      ActiveDocument.UpdateStyles
    End Sub
    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. Could you expand on your statement? It's been a few years since I dabbled with Macros and need to start using them again.

    Okay, so let's say I have 20 MS Word document (.DOC) files. Should I create both a master template and then a macro? All the documents (not .DOT files at this point) use
    the same set of styles.

    With that said, can you give me a macro example that I can expand upon.

    I will essentially take these 20 .DOC files and make them all into .DOT files, but for now, I want to batch through and update all the colors (H1, H2 and table column shading) without having to manually tweak each document.

    Any further thoughts on "the best approach" would be appreciated.

    Thanks again for the assist.

    Jim

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    OK, it sounds like you haven't used a consistent template for the documents so the easy path is not going to work.

    Try modifying this macro to do what you require. This is a more direct implementation that is less likely to have other repercussions
    Code:
    Sub GenericBatcher()
      ' Modify as needed, but keep trailing backslash
      Const strPath = "C:\Documents\"
      Dim strFile As String, aDoc As Document, aTbl As Table
      On Error GoTo ErrHandler
      strFile = Dir(strPath & "*.doc")
      ' Loop through doc files in folder
      Do While Not strFile = ""
        'Steps to be applied to the document
        Set aDoc = Documents.Open(strFile)
        aDoc.Styles("Heading 1").Font.Color = RGB(62, 102, 72)
        aDoc.Styles("Heading 2").Font.Color = RGB(62, 102, 72)
        For Each aTbl In aDoc.Tables
          aTbl.Columns(1).Shading.ForegroundPatternColor = wdColorAqua
        Next aTbl
        aDoc.Close SaveChanges:=True
        ' Go on to the next found file
        strFile = Dir
      Loop
      
    ExitHandler:
      Exit Sub
      
    ErrHandler:
      MsgBox Err.Description, vbExclamation
      Resume ExitHandler
    End Sub
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    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 have been off the forum a few days, but will give that a try today.
    Thanks for the code.

    Regards,

    J

Posting Permissions

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