Consulting

Results 1 to 2 of 2

Thread: Adding footer with a file name, before printing and without deleting existing footer

  1. #1

    Adding footer with a file name, before printing and without deleting existing footer

    Hello,

    I need to create a macro in Word 2010, that will add a footer to documents with the file name, without the extension.

    I found a code that displays the file name without the extension when you use a docvariable field:

    Sub autofilenamefooter()

    Dim fname As String
    fname = ActiveDocument.Name
    fname = Left(fname, InStr(fname, ".") - 1)

    With ActiveDocument

    .Variables("fname").Value = fname

    .PrintPreview
    .ClosePrintPreview

    End With

    End Sub


    How can I use this to create a macro that:

    1. Foots the document with the file name before printing (so that the field will be updated each time you print the document).

    2. In addition, the new footer (with the file name) will not delete existing footers, if any. This requirement is due to the fact that the macro should be applied to all documents in our document management system, and some of the documents already have footers (such as firm papers with logos) that I would like to keep.

    Thanks in advance!

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    You really don't need any macro code different from what you already have to add the filename to the footer; all you need there is the appropriate DOCVARIABLE field. To ensure the Docvariable gets updated when the document is printed requires a DocumentBeforePrint macro, for which the setup is considerably more involved than the usual macro. See: https://wordmvp.com/FAQs/MacrosVBA/I...tSavePrint.htm
    Cheers
    Paul Edstein
    [Fmr 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
  •