OK, let me see if I understand correctly.
You need a single macro that both gets a string from someplace else, AND inserts it into the last page ONLY.
It is that last page ONLY that can be the problem. As I previously posted, there are three footers in each section. Say you have NO section breaks, and you have code that displays the text of each footer in that section. Even though you think you have only one footer, you will get THREE messages, because there are always three footers in every section.
If the requirement is to have it ONLY on the last page, there is no way around this issue. You must make the last page a separate section.
This problem would not be a problem at all if there is not a requirement for the footer to be on the last page ONLY.
Just to demonstrate. say you have a document, five pages long. You make no adjustments to page setup. No different odd/even, no different first page. You put into the footer the text "whatever it is".
If you run code that checks the text of each footer in the section and performs an InStr to see if the footer text contains "whatever". It displays a messagebox with the result, AND the index number of the footer.
You will get THREE message boxes. The first will be 11 - the first 1 indicating the position of the searched for string. "whatever" is at position 1 of "whatever it is". The second 1 is the index of the footer.
The second message will be 02. The 0 is the result of the search. It returns a 0 because the second footer text does NOT contain the searched for string. The second footer does NOT have any text at all.
The third message box will be 03 - for similar reasons.
This is very important, because if you look at the document, there is footer text on EVERY page. However, technically, the second footer object in the Section has NO text, as does the third footer object.
So. If the requirement is it must be on the last page ONLY, and the number of pages can change (and that seems to be a given), you MUST search back through all the footer objects for something that identifies a previous inserted filename.
I am confused with post that refer to templates, and AutoNew routines.
PLEASE - spec out exactly what you want to happen.
Is this a new document?
Is this a previous saved document that may get a new filenumber, and therefore will be saved as a new filename?
Does it have to be on the last page?
As much as Tony may think I possibly make things too complicated (and he is absolutely correct in that sometimes), if the requirement is for:
1. the search for, and removal of, a previous footer containing an old filename;
2. a RE-Sectioning to maintain a separate footer for ONLY the last page;
Then it IS complicated. Do-able, but complicated.
Just to be clear, if you have a IF field in a footer, and you add 20 pages, that if field is still back there - especially if there are new sections.
So what I need to know is:
Is this for a template that will be making a new document, getting a new filename filenumber, and putting it into the last page footer...and is a ONE SHOT DEAL;
OR, is this a document that may change;
OR is the first, but ALSO may change.
Talk to me. I think this can be done. However....uh, you have two days. I fly out early Saturday, and will be mostly unavailable for two weeks. Doing a photo shoot in the redwoods of Northern California. Mmmmmm, yum, cool, fog, and wet.