Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

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

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.