PDA

View Full Version : UPDATING FOOTERS



Greg
07-18-2007, 06:01 PM
Hi all,

I have a Userform into which I type a reference number to populate my document via a bookmark and fields.

However, the number must also appear in the footer of my document. Although I inserted a field for the reference number in the footer, the field will not update automatically with the other data in the document.

I have seen this problem mentioned previously and would be very greatful if you could assist once more.

Regards,

Greg.

fumei
07-19-2007, 07:56 AM
Use StoryRanges. Run code that goes through each StoryRange and updates fields.

Greg
07-19-2007, 06:21 PM
Thanks Gerry but are you sure I can use StoryRanges to upadate fields in headers/footers? In my search for an answer I found an article at the TechTrax site (see the link below). It seems like a very convoluted way of doing things. There must be a better way. Would you care to comment on this.
http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=585

fumei
07-20-2007, 01:50 AM
Sub UpdateALL()
Dim oStory As Object
Dim oToc As Object

'exit if no document is open
If Documents.Count = 0 Then Exit Sub
Application.ScreenUpdating = False

For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update 'update fields in all stories
Next oStory

For Each oToc In ActiveDocument.TablesOfContents
oToc.Update 'update TOC's
Next oToc

Application.ScreenUpdating = True
End Sub
From the KB....

Greg
07-20-2007, 02:25 AM
Thanks Gerry but that doesn't work automatically for me. It does work if I run the macro separately but it's very, very slow.

I want this to work when I press OK on my userform and I want it to work quickly. Do you have any more ideas?

Regards,

greg.

fumei
07-20-2007, 01:23 PM
Excuse me????

"that doesn't work automatically"

"I want this to work when I press OK on my userform"

Seems rather contradictory.

So...ummm, the OK button is pressed now somehow automatically???? It can be executed automatically, or by pressing OK.

Sheeesh.

I am not sure why it would be very very slow. Did you notice it also updated a Table of Contents (if you have one). Did you remove that part of the code, if not applicable?

Care to actually describe your situation? Do you have a lot of footnotes? They are a separate StoryRange. There are 11 Stories in a Word document. So if you have content there...it could get slow going through.

How many footers? How many Sections? Do you have DifferentFirstPage? DifferentOddEven?

If there is just the one footer (in one Section), then you can simply update the fields directly in THAT footer.
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary) _
.Range.Fields.Update

Greg
07-22-2007, 12:59 AM
Gerry,

There are 4 sections in the document and I want the all the fields in the footers to update when I click OK on the userform. At present I have to run the macro separately through tools/macros/run.

Greg.

Greg
07-22-2007, 01:05 AM
Gerry,

I should have added that all 4 footers are "same as previous".

fumei
07-22-2007, 07:43 AM
If all 4 footers are same as previous, then there is only one in terms of content. Update that one.

Uh, if you have to run the macro through tools/macro, then you coded it wrong. It can run through your OK button. Just put the code there.

Greg
07-22-2007, 09:26 PM
Gerry, why do I need special code when the other macros in that document work beautifully without it?

Anyway, I doubt that I'll solve this alone so I would appreciate another clue from you. My efforts so far have not been very fruitful and I still need to run the UpdateFooter macro separately. I can't get it to fire with the OK button on my userform.

Charlize
07-23-2007, 02:48 AM
Call UpdateALLplaced in the click event of the userformbutton should work.

fumei
07-23-2007, 02:57 AM
I can't get it to fire with the OK button on my userform.Why on earth not??? It is a procedure, just like any other procedure. There is nothing special about it.

Do it as a Call, as Charlize suggests, or put the actual instructions into the OK button _Click event. There is absolutely NO reason your userform button can not do this. I can do it.

Oh....is your document protected for forms? If so, you do need to unprotect.