Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

VBA into already created table(s) in a Header or Footer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brendan - 08 Aug 2006 18:35 GMT
MS Word - VBA into Header or Footer (and into a table in the same)

Is there a way to allow gain access to a header or footer in Word via VBA?  
I have a one page form full of tables (Page 1) and the narrative begins on
Page 2.  There is a header and footer on page 2 and subsequent pages (but not
on page 1).  The header and footer have tables and I need to be able to
bookmark the tables somehow and copy certain data from page 1 to this header
and footer.  

As I see it, there are two ways to do it:

#1 Use a VBA “prompt box” (UserForm) for the data to be captured and force
the data into the header for footer as well as certain fields on Page 1.

OR

#2 Have a macro run on a Text Form Field "EXIT" which automatically COPIES
and PASTES data from Page 1 to the header & footer on Page 2

I have tried where “tblLastFirstMiddle” is the Form Text Field / Bookmark
and vLastFirstMiddle is the text box control on VBA UserForm.

ActiveDocument.FormFields("tblLastFirstMiddle").Result =
vLastFirstMiddle.Value

This works fine for Page 1 but I have yet to be able to (1) manually place a
bookmark / text form field in an already created header or footer and (2)
call that bookmark in the header or footer and (3) Copy and Paste the data
into it.

Any suggestions?
Jonathan West - 08 Aug 2006 18:46 GMT
> MS Word - VBA into Header or Footer (and into a table in the same)
>
[quoted text clipped - 16 lines]
> #2 Have a macro run on a Text Form Field "EXIT" which automatically COPIES
> and PASTES data from Page 1 to the header & footer on Page 2

#3 Place a REF field in the header that references the bookmark which marks
the formfield on Page 1.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Brendan - 08 Aug 2006 19:25 GMT

> #3 Place a REF field in the header that references the bookmark which marks
> the formfield on Page 1.

If the bookmark (formfield) name on Page 1 is docLastFirstMiddle, can you
give me an example of what you mean?
Brendan - 08 Aug 2006 19:43 GMT
I have tried the INSERT, FIELD and {REF docLastFirstMiddle} which did not work.
I also tried the INSERT, REFERENCE and {{REF docLastFirstMiddle \h} which
also did not work.  Is there some sort of update code that I have to run?
Brendan - 08 Aug 2006 22:10 GMT
Update:  The REF works fine but the only way to view it on the fly was to
create two lines of code which run after the prompt box is closed.  This acts
like a document refresh which then allows the user to see that the data was
actuall filled in the header and footer:

ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview

If there is another "refresh" or "requery" type command, can someone please
let me know.  Thanks, Brendan

> I have tried the INSERT, FIELD and {REF docLastFirstMiddle} which did not work.
> I also tried the INSERT, REFERENCE and {{REF docLastFirstMiddle \h} which
> also did not work.  Is there some sort of update code that I have to run?
Jonathan West - 08 Aug 2006 23:27 GMT
> Update:  The REF works fine but the only way to view it on the fly was to
> create two lines of code which run after the prompt box is closed.  This
[quoted text clipped - 9 lines]
> please
> let me know.  Thanks, Brendan

Something like this should work

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Fields.Update

If the first section is protected, you may need to Unprotect the document,
run that line, and then Protect it again.

Signature

Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org

Brendan - 08 Aug 2006 23:59 GMT
Works Perfect!  Thank You very much.

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Fields.Update
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.