?
Solved

Dynamic footer depending on entry in main document

Posted on 2010-08-23
4
Medium Priority
?
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial provides instructions on how to properly format your Word document using the inbuilt tools provided. The benefits of using these tools means your documents are more accessible and easily portable to other applications an…
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
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.
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

649 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