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?

Re: VBA into already created table(s) in a Header or Footer by Jonathan

Jonathan
Tue Aug 08 12:46:48 CDT 2006


"Brendan" <Brendan@discussions.microsoft.com> wrote in message
news:78335B9C-D062-49B5-961D-6FA46B0C3F57@microsoft.com...
> 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
>

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


--
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




Re: VBA into already created table(s) in a Header or Footer by Brendan

Brendan
Tue Aug 08 13:25:02 CDT 2006



"Jonathan West" wrote:

> #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?

Re: VBA into already created table(s) in a Header or Footer by Brendan

Brendan
Tue Aug 08 13:43:01 CDT 2006

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?

Re: VBA into already created table(s) in a Header or Footer by Brendan

Brendan
Tue Aug 08 16:10:02 CDT 2006

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

"Brendan" wrote:

> 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?

Re: VBA into already created table(s) in a Header or Footer by Jonathan

Jonathan
Tue Aug 08 17:27:50 CDT 2006


"Brendan" <Brendan@discussions.microsoft.com> wrote in message
news:1BFC55CC-3A1D-4B38-B11B-573A4CF44D45@microsoft.com...
> 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

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.


--
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



Re: VBA into already created table(s) in a Header or Footer by Brendan

Brendan
Tue Aug 08 17:59:01 CDT 2006

Works Perfect! Thank You very much.

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