table in header

Z

zfox

the situation:
i have a word document that has a header and a footer
in this header there is a single table with 1 row and 3 columns
how can i go ,by vba code, to that table

what i want to do:
using vb6,i instanciate that document out of a template with automation
and i want to fill that table in the header with data from an access
database
tia
 
J

Jean-Guy Marcil

zfox was telling us:
zfox nous racontait que :
the situation:
i have a word document that has a header and a footer
in this header there is a single table with 1 row and 3 columns
how can i go ,by vba code, to that table

what i want to do:
using vb6,i instanciate that document out of a template with
automation and i want to fill that table in the header with data from
an access database
tia

In which header is the table located? The primary header of the first
section? The first-page header of the second section? The odd-page header of
the first section? etc.
Assuming you meant the primary header of the first section and that the
table you want is the first one in the header, something like this would
work:

'_______________________________________
Dim tblHeader As Table

Set tblHeader = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Range.Tables(1)

With tblHeader
.Cell(1, 1).Range.Text = "First Cell"
.Cell(1, 2).Range.Text = "Second Cell"
.Cell(1, 3).Range.Text = "Third Cell"
End With
'_______________________________________

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
P

PC

Thank you very very much,merci beaucoup
however,now i have done as you suggested,i realize what i want to do is not
possible that way,my bad
i'll try to explain what i want to do
i have this word document, that has a header and a footer, this header and
footer has to appear on every page.
that i can do.
in the top of the header,one can put any kind of text over the entire width
of the header
under that text,one can put any kind of text but only on the left half of
the header
next to that text,on the right half of the header,i need some kind of
textarea that i can fill in with vba code
that textarea has to be positioned exactly,it can not change position,and it
has to be multiple lines
but whatever text i put in it with code,its position,left,top,width should
not change,even if i put in more text then it can hold
(this textarea is in fact an adres that has to be aligned with a 'window' in
an enveloppe)
hope you can help me
please do not reply in french,as my english,bad as it is,is stil far better
than my french
merci beaucoup beaucoup beaucoup
 
J

Jean-Guy Marcil

PC was telling us:
PC nous racontait que :
Thank you very very much,merci beaucoup
however,now i have done as you suggested,i realize what i want to do
is not possible that way,my bad
i'll try to explain what i want to do
i have this word document, that has a header and a footer, this
header and footer has to appear on every page.
that i can do.
in the top of the header,one can put any kind of text over the entire
width of the header
under that text,one can put any kind of text but only on the left
half of the header
next to that text,on the right half of the header,i need some kind of
textarea that i can fill in with vba code
that textarea has to be positioned exactly,it can not change
position,and it has to be multiple lines
but whatever text i put in it with code,its position,left,top,width
should not change,even if i put in more text then it can hold
(this textarea is in fact an adres that has to be aligned with a
'window' in an enveloppe)
hope you can help me
please do not reply in french,as my english,bad as it is,is stil far
better than my french
merci beaucoup beaucoup beaucoup

Insert a textbox in your header. Set its Line to "No Line". Make it just a
little bigger than what you need.
Inside the textbox, create a one-row/one-column table.Make it exactly the
size you need it. Make sure that the row height is set to "Exactly" the
height you need and uncheck the "Automatically resize to fit content"
options from the Options button on the Table tab of the Table Properties
dialog.

Finally, in your code, use this to refer to that table (Assuming, again,
that you are using the primary header of Section 1, and that this header
contains only one textbox which contains only one table).

Dim tblHeader As Table

Set tblHeader = ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Range _
.ShapeRange(1).TextFrame.TextRange.Tables(1)

With tblHeader
.Cell(1, 1).Range.Text = "My text"
End With

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
P

PC

Jean-Guy
i tried your last suggestion, and it works,merci beacoup beacoup beacoup
then after studying your code i tried:

Sub FactuurAdres()
Dim FactuurAdres As String
FactuurAdres = "Adresline1" & vbCrLf & "Adresline2" & vbCrLf &
"Adresline3"
ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Range _
.ShapeRange(1).TextFrame.TextRange.Text = FactuurAdres
End Sub

and it worked to,hurray
then i added some wordart in the header...it stopped working
i changed '.ShapeRange(1)' to '.ShapeRange(2)'...and it worked again
so i tried out with more than 1 textbox and more than 1 wordart
i found that '.ShapeRange(1)' is the object that is highest placed in the
header,'.ShapeRange(2)' the next highest,etc...
this was kind of a problem
so i remembered i had seen on your webside something "How to find and
replace text anywhere in a document"
so i tried that...and it worked...kind of
i typed <FactuurAdres> in some textboxes in several places in a document
and tried to find <FactuurAdres> and replace it with the string "Adresline1"
& vbCrLf & "Adresline2" & vbCrLf & "Adresline3"
and it worked...kind of
<FactuurAdres> was everywhere replaced with 'Adresline1'...not exactly what
i wanted
after some tries,with everytime the same result, i placed the cursor after
Adresline1,pushed 'DEL'
and lo, Adresline2 appeared, did the same after Adresline2 and Adresline3
appeared
so i type <FactuurAdres> in a textbox and hit 'ENTER'
and after the the find and replace it was replaced with:
Adresline1
Adresline2
Adresline3
just what i wanted
i stil had to change the string "Adresline1" & vbCrLf & "Adresline2" &
vbCrLf & "Adresline3"
with
the string "Adresline1" & vbCr & "Adresline2" & vbCr & "Adresline3"
and now it works exactly the way i want,all thanks to you
thank you very very very much
 
J

Jean-Guy Marcil

PC was telling us:
PC nous racontait que :
Jean-Guy
i tried your last suggestion, and it works,merci beacoup beacoup
beacoup then after studying your code i tried:

Sub FactuurAdres()
Dim FactuurAdres As String
FactuurAdres = "Adresline1" & vbCrLf & "Adresline2" & vbCrLf &
"Adresline3"
ActiveDocument.Sections(1) _
.Headers(wdHeaderFooterPrimary).Range _
.ShapeRange(1).TextFrame.TextRange.Text = FactuurAdres
End Sub

and it worked to,hurray
then i added some wordart in the header...it stopped working
i changed '.ShapeRange(1)' to '.ShapeRange(2)'...and it worked again
so i tried out with more than 1 textbox and more than 1 wordart
i found that '.ShapeRange(1)' is the object that is highest placed in
the header,'.ShapeRange(2)' the next highest,etc...
this was kind of a problem
so i remembered i had seen on your webside something "How to find and
replace text anywhere in a document"
so i tried that...and it worked...kind of
i typed <FactuurAdres> in some textboxes in several places in a
document and tried to find <FactuurAdres> and replace it with the
string "Adresline1" & vbCrLf & "Adresline2" & vbCrLf & "Adresline3"
and it worked...kind of
<FactuurAdres> was everywhere replaced with 'Adresline1'...not
exactly what i wanted
after some tries,with everytime the same result, i placed the cursor
after Adresline1,pushed 'DEL'
and lo, Adresline2 appeared, did the same after Adresline2 and
Adresline3 appeared
so i type <FactuurAdres> in a textbox and hit 'ENTER'
and after the the find and replace it was replaced with:
Adresline1
Adresline2
Adresline3
just what i wanted
i stil had to change the string "Adresline1" & vbCrLf & "Adresline2" &
vbCrLf & "Adresline3"
with
the string "Adresline1" & vbCr & "Adresline2" & vbCr & "Adresline3"
and now it works exactly the way i want,all thanks to you
thank you very very very much

Not sure I follow all that, but I'm glad to see you sorted it out on your
own.

By the way, it is not MY website...

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top