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 / February 2007

Tip: Looking for answers? Try searching our database.

wdHeaderFooterPrimary wdHeaderFooterPrimary

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Senad Isanovic - 26 Feb 2007 09:16 GMT
Need to know how to refer to first page in the document (not just to first
section) no matter if is different first page or not. Below I have a range
that refers to footer in the first section but I need the just the first
page. Thanks

   Set myrange =
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range
   myrange.Collapse WdCollapseDirection.wdCollapseEnd

   Set myfooter = ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
   AddTxtbox sRef, myrange, myfooter, top
Jezebel - 26 Feb 2007 09:51 GMT
Are you trying to refer to the page, or to the first page headers and
footers?

> Need to know how to refer to first page in the document (not just to first
> section) no matter if is different first page or not. Below I have a range
[quoted text clipped - 8 lines]
> ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
>    AddTxtbox sRef, myrange, myfooter, top
Senad Isanovic - 26 Feb 2007 15:20 GMT
First page footer (on the first page of the document)

> Are you trying to refer to the page, or to the first page headers and
> footers?
[quoted text clipped - 11 lines]
>> ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
>>    AddTxtbox sRef, myrange, myfooter, top
Jezebel - 26 Feb 2007 23:36 GMT
Dim pRange As Word.Range

   on error resume next
   If ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter Then
       Set pRange = ActiveDocument.StoryRanges(wdFirstPageFooterStory)
   Else
       Set pRange = ActiveDocument.StoryRanges(wdPrimaryFooterStory)
   End If
   on error goto 0

You need the error-handler in case there's no footer at all.

> First page footer (on the first page of the document)
>
[quoted text clipped - 13 lines]
>>> ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
>>>    AddTxtbox sRef, myrange, myfooter, top
Senad Isanovic - 27 Feb 2007 09:33 GMT
Great! And if I want to do in the similay way for a HeaderFooter variable,
how can that be done? The reason that I'm asking is that I need to pass both
myrange and myfooter to AddTxtbox procedure. That procedure adds a textbox
in the footer on the first page on the document. This works fine if the
first section only has one page but if the first section of the document
contains several pages then the textbox is added on all pages if the first
section which is not what I want. Thanks!

Dim myfooter As HeaderFooter
   If ActiveDocument.PageSetup.DifferentFirstPageHeaderFooter Then
       Set myrange = ActiveDocument.StoryRanges(wdFirstPageFooterStory)
       Set myfooter =
ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage)
   Else
       Set myrange = ActiveDocument.StoryRanges(wdPrimaryFooterStory)
       Set myfooter =
ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage)
       myfooter.LinkToPrevious = False
   End If

myrange.Collapse WdCollapseDirection.wdCollapseEnd
AddTxtbox sRef, myrange, myfooter, top
Jezebel - 27 Feb 2007 10:48 GMT
This has to do with how your document is set up, rather than your code. If
the first section of your document has more than one page, and is not set up
with a different first page footer, then adding something to the footer will
add it to every page of that section. That's the way headers and footers
work. If you need the object on the first page only, you need to set
DifferentFirstPageHeaderFooter to TRUE.

> Great! And if I want to do in the similay way for a HeaderFooter variable,
> how can that be done? The reason that I'm asking is that I need to pass
[quoted text clipped - 18 lines]
> myrange.Collapse WdCollapseDirection.wdCollapseEnd
> AddTxtbox sRef, myrange, myfooter, top
Senad Isanovic - 27 Feb 2007 15:35 GMT
Ok, I understand. My issue is that I need to add a textbox with unique
document number in the footer of the first page of the document, no matter
if the document has different first page or not, and no matter if you have
several pages in the first section of the doc. Changing the page setup to
different first page (if is not different first page already) is not a
proper solution because if an existing footer is there on the first page it
may disappear which is not what I want.. So any other solution? Mayby using
the code below and trying to add a textbox, is not the right way to do
this.. Thank you, /Senad
Jean-Guy Marcil - 27 Feb 2007 19:44 GMT
Senad Isanovic was telling us:
Senad Isanovic nous racontait que :

> Ok, I understand. My issue is that I need to add a textbox with unique
> document number in the footer of the first page of the document, no
[quoted text clipped - 5 lines]
> want.. So any other solution? Mayby using the code below and trying
> to add a textbox, is not the right way to do this.. Thank you, /Senad

Does the text have to be in the footer?
Why can't you just add it tot he bottom of the first page directly?

If not, you can detect the type of footer and code for the addition of a
different first page footer like this (In pseudo code):

Detect if first section has a different first page footer
   If ActiveDocument.Sections(1).PageSetup.DifferentFirstPageHeaderFooter
Then
       MsgBox "First section has a different first page footer."
   Else
       MsgBox "First section does not have a different first page footer."
   End If
If so, add your textbox > End
If not,
Add the diffrent first page header/footer to the first section
Copy the content of the primary footer to the first page footer
   With ActiveDocument.Sections(1)
       With .Footers
           .Item(wdHeaderFooterFirstPage).Range.FormattedText = _
               .Item(wdHeaderFooterPrimary).Range.FormattedText
           'Remove superfluous ¶
           .Item(wdHeaderFooterFirstPage).Range.Paragraphs.Last.Range.Delete
       End With
   End With
Repeat for the header
Add your textbox to the footer > End

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Senad Isanovic - 28 Feb 2007 15:27 GMT
Many Thanks for a very good answer.

>>Does the text have to be in the footer? Why can't you just add it tot he
>>bottom of the first page directly?

No it does not have to in the footer, I can add it at the bottom of the
first page or in the left margin of the first page. The only thing that is
important is that it is somewhere on the first page and that the user can
not easily delete this unique document number. That was the original reason
to why I 'm adding a textbox in the footer. I tried also to add a little
table with only one cell on the first page and then to read/write the unique
number to that cell in my table but the document can contain one or several
other tables too and I don't know how to refer to my little table.

Can I name the table to something unique instead of using the table index
number?

ActiveDocument.Tables(1).Rows(1).Cells(1).Range.Text = "INT98878-v1"
Jean-Guy Marcil - 28 Feb 2007 18:09 GMT
Senad Isanovic was telling us:
Senad Isanovic nous racontait que :

> Many Thanks for a very good answer.
>
[quoted text clipped - 6 lines]
> that the user can not easily delete this unique document number. That
> was the original reason to why I 'm adding a textbox in the footer. I

Then it is probably best to use the footer to avoid accidental deletion.

> tried also to add a little table with only one cell on the first page
> and then to read/write the unique number to that cell in my table but
[quoted text clipped - 4 lines]
>
> ActiveDocument.Tables(1).Rows(1).Cells(1).Range.Text = "INT98878-v1"

No, you cannot name tables, but, you can assign a bookmark to a table, as in
this sample code that assumes that you have already  made sure that section
1 in the document has a different first page footer:

'_______________________________________
Dim tblID As Table
Dim rgeFooter As Range
Const strTableName As String = "Table_ID"

'Set the range in the footer that already has a diffrent first page footer
Set rgeFooter = ActiveDocument.Sections(1).Footers(wdHeaderFooterFirstPage)
_
   .Range.Paragraphs(1).Range
rgeFooter.Collapse wdCollapseStart

'Add a table in that footer and assign bookmark
Set tblID = rgeFooter.Tables.Add(rgeFooter, 1, 1)
'set width
tblID.Columns(1).Width = InchesToPoints(1.25)
ActiveDocument.Bookmarks.Add strTableName, tblID.Range

'To use the table in the bookmark
With ActiveDocument.Bookmarks(strTableName).Range.Tables(1)
   .Cell(1, 1).Range.Text = "INT98878-v1"
End With
'_______________________________________

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org


Rate this thread:






 
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.