AddTexBox to wdHeaderFooterFirstPage does not work

W

Ward Visser

Hi all,

I want to add 1TextBox and 2 Pictures to the wdHeaderFooterFirstPage and
no TextBox and 2 other Pictures to the other Headers of all pages exept the
first (wdHeaderFooterPrimary)

The Picture-part works fine but not the TextBox.
Next code generates a TextBox in the Headers of all pages exept the required
and expected first FirstPage:

*****
Dim myDoc As Word.Document
Dim myShape As Word.Shape
Set myDoc = ActiveDocument

myDoc.PageSetup.DifferentFirstPageHeaderFooter = True

Set myShape =
myDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddTextbox _
(Orientation:=msoTextOrientationHorizontal, _
Left:=CentimetersToPoints(1), _
Top:=CentimetersToPoints(2.5), _
Width:=CentimetersToPoints(4), _
Height:=CentimetersToPoints(6))

With myShape
.Name = "AdresPA"
.TextFrame.TextRange = "Test"
End With
*****

What am i doing wrong?
Thank you,

Ward.
 
W

Ward Visser

Me again,

It becomes stranger to me.

Using Dave Rado's sample code, position a floating object, gives the same
result.
http://www.mvps.org/word/FAQs/DrwGrphcs/PosRelToPage.htm
I only added the line:
ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True
(I'am using a dutch WindowsXP and an english OfficeXP)

Result: no lines on the first page, but lines on all the other pages!

Please help me if you know what i am doing wrong.

Thank you,
Ward

*****
Dave Rado's code:

Sub AddLinesToHeader()

Dim oHeader As HeaderFooter, MyRange As Range, oLine As Shape
System.Cursor = wdCursorWait

ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter = True

Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)
'Make sure the shape anchored to the final paragraph in the Header
Set MyRange = oHeader.Range.Paragraphs.Last.Range

Set oLine = oHeader.Shapes.AddLine(0, 0, 0, 0, Anchor:=MyRange)
With oLine
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Width = CentimetersToPoints(1)
.Left = CentimetersToPoints(0.5)
.Top = CentimetersToPoints(21.76)
.LockAnchor = True
.WrapFormat.Type = wdWrapNone
'It's a good idea to name shapes you add, so that if you want to hide
them,
'or whatever later, you can refer to them by name
.Name = "First Line"
'Add any other parameters you need, eg .Line.Weight = etc
End With

Set oLine = oHeader.Shapes.AddLine(0, 0, 0, 0, Anchor:=MyRange)
With oLine
.RelativeHorizontalPosition = wdRelativeHorizontalPositionPage
.RelativeVerticalPosition = wdRelativeVerticalPositionPage
.Width = CentimetersToPoints(1)
.Left = CentimetersToPoints(0.5)
.Top = CentimetersToPoints(22.08)
.LockAnchor = True
.WrapFormat.Type = wdWrapNone
.Name = "Second Line"
'add other parameters you need, eg .Line.Weight = etc
End With

System.Cursor = wdCursorNormal

End Sub
 
T

Thomas Winter

Sorry, I haven't been following this from the beginning, but it sounds like
your problem is in the line:

Set oHeader = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary)

You want to use the constant wdHeaderFooterFirstPage instead in order to get
your lines on the first page. The "Primary" header/footer is the one that
starts on page 2 when you have a different first page header/footer.

-Tom
 
W

Ward Visser

Thank you Thomas,

I changed Dave's code. It worked. Then modified it to add my TextBox on the
FirstPage: It worked too!

I still don't know what was wrong with my first code, but i don't care: i
have a good/better alternative.

Regards,

Ward
 

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