0

I have a macro in a Word document that generates a footer based on Bookmarks. It works, except for one detail: in one of the Ref-fields in the footer, the font is always incorrect after updating.

The size should be 6, like the rest of the footer, but is 9.5, like the original text. This only happens with one field. I've checked that the paragraph sign and the whole line are formatted properly. I've even copied one of the functions bookmarks and adapted them, but the font size is always wrong.

The problem arises on several computers.

I've given up solving the original problem because I'm running out of ideas. What I want now is to add to the macro some code that will apply a certain style (or font) to the footer.

What I've tried so far:

  • I have created a Style for the footer (called footer1) - before that it was non-defined
  • I have dabbled with VBA and googled for a few hours now to no avail.
  • Disabling/Enabling mergefield switches in the Ref-field
  • Google Search for "apply style to footer word vba"

Failed attempts:

ActiveDocument.Sections(ActiveDocument.Sections.Count) _
        .Footers(1).Range.Style("footer1")

Here's the code:

ActiveDocument.Fields.Update
ActiveDocument.Sections(ActiveDocument.Sections.Count) _
        .Footers(1).Range.Fields.Update
' code needed here for changing footer's style to "footer1" 
' Alternative: apply style only to faulty ref field.

Thanks for your help.

I can do minor adjustments to VBA macros in a pinch, but I'm no expert. I simply haven't found anything that I could adapt to my needs.

5
  • The font is always false... What does this mean?
    – Dave
    Aug 15, 2013 at 12:31
  • @DaveRook I've edited my question with a more detailed description of the original problem. Aug 15, 2013 at 14:30
  • I made a slight adjustment, hope this is OK.
    – Dave
    Aug 15, 2013 at 14:53
  • What happens if you use ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(1).Range.Font.Size = 6? Doesn't it change the font size to 6 px? At least for me it does.
    – nixda
    Aug 15, 2013 at 14:57
  • @nixda Oh, yes it worked. I love you! Write the answer. Aug 15, 2013 at 15:31

1 Answer 1

4

To change the font size for a specific footer in Word, use Range.Font.Si‌​ze

ActiveDocument.Sections(1).Footers(1).Range.Font.Size = 6

Syntax explained

  • ActiveDocument: A Document object that represents the active document. Other ways to access Word files are Document(index) or Document("Fullname")

  • .Sections(index): A section is a complicated concept in Word. Users are allowed to insert sections into a document so they can change formatting in a particular area of a document. Manual breaks and section breaks divide your page into separate sections where each can have a different formatting. Changing one footers properties doesn't always mean all footers are changed.
    Read here for more.

    In VBA, when using Sections.Count as the index parameter for .Sections(index), it will always represent the last section of your document

  • .Footers(index): Represents a single Footer area in the top, bottom, or side margins of each page in a document. Other commonly used properties for sections are border, header or range which stands for the complete body within the given section

  • Footers(index).Range: Represents the portion of a document that is contained within the specified header or footer. Note the difference to Sections(index).range

  • Font.Si‌​ze: One of the many properties a font can have. Other common properties for footers are Words(index) to alter specific words, Fields or just Text to read in the complete footer text

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .