Protected word template - vb/macro to update footer

Discussion in 'Word' started by tmc, Jan 9, 2017.

  1. tmc

    tmc

    Joined:
    Jan 9, 2017
    Messages:
    4
    Likes Received:
    0
    I have a word template that is protected, trying to set the footer so that it updates to the file name when opening and closing the document. I can't seem to figure out the correct macro or vb for it.
    The closest I've gotten is this:

    ' If document is protected, unprotect it.
    If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect Password:=""
    ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Text = ActiveDocument.FullName
    End If

    However, it does not update the footer with the file name at opening or closing the docx.
     
    tmc, Jan 9, 2017
    #1
    1. Advertisements

  2. tmc

    macropod Microsoft MVP

    Joined:
    Mar 2, 2012
    Messages:
    178
    Likes Received:
    10
    Why not use a FILENAME field in the footer? No macros required.
     
    macropod, Jan 9, 2017
    #2
    1. Advertisements

  3. tmc

    tmc

    Joined:
    Jan 9, 2017
    Messages:
    4
    Likes Received:
    0
    Tried the filename in the footer. Doesn't update when the filename is changed due to the required protection on the doc.
     
    tmc, Jan 9, 2017
    #3
  4. tmc

    macropod Microsoft MVP

    Joined:
    Mar 2, 2012
    Messages:
    178
    Likes Received:
    10
    With the FILENAME field in place, you could use a macro coded as:
    Code:
    Private Sub Document_Open()
    Application.ScreenUpdating = False
    With ActiveDocument
      .PrintPreview
      .ClosePrintPreview
    End With
    Application.ScreenUpdating = True
    End Sub
     
    macropod, Jan 10, 2017
    #4
  5. tmc

    tmc

    Joined:
    Jan 9, 2017
    Messages:
    4
    Likes Received:
    0
    macropod: that did not work.

    I can't even figure out how to unprotect the footer field. Word is much more convulted than excel.
     
    tmc, Jan 10, 2017
    #5
  6. tmc

    macropod Microsoft MVP

    Joined:
    Mar 2, 2012
    Messages:
    178
    Likes Received:
    10
    There is nothing that needs unprotecting via the macro. Once the field is in the footer (which you have to unprotect to do - meaning it should be done to the form's template, not to each form individually), the macro I posted is all that's needed to update it. Simply add it to the template's 'ThisDocument' code module. Added there, you can even save the documents in the docx format, since they don't need the macro. Furthermore, by using the field, the document name in the footer will update if ever the filename/path is changed - which code along the lines of what you were trying to do would be incapable of.
     
    macropod, Jan 10, 2017
    #6
  7. tmc

    tmc

    Joined:
    Jan 9, 2017
    Messages:
    4
    Likes Received:
    0
    Nothing suggested has worked. :(
    The template is set to restricted formatting and editing this is to prevent the template from being changed except in the fields indicated. Doing a file save as then saving the dotx with a new name as a docx does not update the footer. Closing the document and reopening the document does not change the footer. However, going into print preview then closing print preview does update the footer correctly.
    I'm out of ideas...
     
    tmc, Jan 12, 2017
    #7
  8. tmc

    macropod Microsoft MVP

    Joined:
    Mar 2, 2012
    Messages:
    178
    Likes Received:
    10
    Did you add the macro to the template's 'ThisDocument' code module?
     
    macropod, Jan 13, 2017
    #8
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. kittykatoo
    Replies:
    1
    Views:
    556
    macropod
    Jun 13, 2012
  2. GordonM
    Replies:
    0
    Views:
    859
    GordonM
    Apr 25, 2014
  3. Rajan Kandola
    Replies:
    0
    Views:
    961
    Rajan Kandola
    May 6, 2014
  4. bursal

    Heading and footer numbering

    bursal, Aug 9, 2014, in forum: Word
    Replies:
    0
    Views:
    325
    bursal
    Aug 9, 2014
  5. gerimo
    Replies:
    0
    Views:
    247
    gerimo
    Feb 19, 2015
  6. Gemma

    Page Numbering On Footer

    Gemma, Mar 5, 2015, in forum: Word
    Replies:
    0
    Views:
    237
    Gemma
    Mar 5, 2015
  7. Luxanais
    Replies:
    0
    Views:
    233
    Luxanais
    Sep 24, 2015
  8. Nikhil
    Replies:
    0
    Views:
    238
    Nikhil
    Feb 25, 2016
Loading...