Solved

Dynamic footer depending on entry in main document

Posted on 2010-08-23
4
434 Views
Last Modified: 2012-08-13
I'm trying to get a quote templace to show the quote number in the footer.

Most viable way seemed to use a textbox, in the text bpdy and use the textbox/change event to trigger the VBA to rewrite the footer accordingly.

It works perfectly except for one nast detail: when the used taps 2-3 character quickly, the textbox gets deleted. Odd, but it happens on both tested computers.

Looking for a fix or alternate solutions than a text box.

Attached a sample document.
The code is below:

rivate Sub TextBox1_Change()
Dim oRge As Range

ActiveDocument.Sections.Item(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Range.Text = ""
Set oRge = EndOfLastFooter()
oRge.Text = "Page "
oRge.Collapse wdCollapseEnd
oRge.Fields.Add Range:=oRge, Type:=wdFieldPage
Set oRge = EndOfLastFooter()
oRge.Text = " of "
Set oRge = EndOfLastFooter()
oRge.Collapse wdCollapseEnd
oRge.Fields.Add Range:=oRge, Type:=wdFieldNumPages
Set oRge = EndOfLastFooter()
oRge.Text = vbTab & TextBox1.Value
Set oRge = EndOfLastFooter()
oRge.Collapse wdCollapseEnd
oRge.Text = vbTab & "   SP/01/03/175/I"

With ActiveDocument.Sections
  Set oRge = .Item(.Count).Footers(wdHeaderFooterPrimary).Range
End With

oRge.Fields.Update
Set oRge = Nothing

End Sub

Private Function EndOfLastFooter() As Range
  Dim oRg As Range
  With ActiveDocument.Sections
    Set oRg = .Item(.Count).Footers(wdHeaderFooterPrimary).Range
  End With
  oRg.Collapse wdCollapseEnd
  Set EndOfLastFooter = oRg
  Set oRg = Nothing
End Function


test.doc
0
Comment
Question by:calacuccia
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 33502319
Yes, I get the same error in Word 2007.

I have tried using the LostFocus event, but that causes Word to Hang in both 2003 and in 2007.

You might be able to use a text input form field in a protected section, and a REF field in the footer, but the restrictions with forms protection might not be acceptable.

Or you could have use a Userform to capture the data and to insert it in the places that you need it.

Incidentally, the Sections collection has a Last method.

  Set oRg = ActiveDocument.Sections.Last.Footers(wdHeaderFooterPrimary).Range

0
 
LVL 17

Author Comment

by:calacuccia
ID: 33508705
Hi Graham,

I certainly find this behaviour very unexpected, for a control to disappear like that. Once again, I loose Word confidence :-)

Formfields is no option: this document is basically edittable from Start to End for some exception, it would become a burden if formfiels had to be used all over this document.

I hope I can prevent to have to use a UserForm, but that would probably work.

Why do you mention the Last method? I did not see where this could help.
0
 
LVL 17

Author Comment

by:calacuccia
ID: 33563344
One last try to bring this to somebody's attention (also known as bump)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now