Roderick
11-23-2017, 05:37 PM
I have a document in Word 2013 which has headers and footers. Both contain a table with logos, date and reference number.
The footer has a bookmark in one of the cells which will eventually hold a piece of text and will be written into that bookmark through a VBA sub-routine. I have made my bookmarks visible so that I can see what happens to them later on.
I now write some text in the document to fill a few pages and the bookmarks are still visible in the footers.
I then place my cursor at random at at paragraph mark in the text and, through VBA, I create a landscape page. I check my bookmarks and they are still there all through the document.
The next procedure is to unlink the headers and footers from the landscape page so that I can make the tables in the header and footer fill the width of the page.
It is as I unlink the header and footer of the landscape page that the bookmark disappears from it and so on through the rest of the document.
This is the code that I am using:
'sets up the new landscape page
With Selection.PageSetup
.Orientation = wdOrientLandscape
.TopMargin = CentimetersToPoints(2.2)
.BottomMargin = CentimetersToPoints(2)
.LeftMargin = oLeftMargin
.RightMargin = oRightMargin
.HeaderDistance = CentimetersToPoints(1.5)
.FooterDistance = CentimetersToPoints(0.7)
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
End With
'=========================================
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
On Error Resume Next
Selection.HeaderFooter.LinkToPrevious = False
With ActiveWindow.ActivePane.View
.PreviousHeaderFooter
.NextHeaderFooter
End With
'==============================================
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
On Error Resume Next
Selection.HeaderFooter.LinkToPrevious = False
With ActiveWindow.ActivePane.View
.PreviousHeaderFooter
.NextHeaderFooter
End With
'===========================================
'changes the widths of the tables in the header and footer
With Selection
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).PreferredWidth = CentimetersToPoints(24.15)
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Columns.Distrib uteWidth
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1).PreferredWidth = CentimetersToPoints(24.15)
End With
With Selection.HeaderFooter.PageNumbers
.RestartNumberingAtSection = False
End With
With ActiveWindow.ActivePane.View
.NextHeaderFooter
End With
With Selection.HeaderFooter.PageNumbers
.RestartNumberingAtSection = False
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
It's when I get to this set of code that the bookmark gets erased from the footer:
'==============================================
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
On Error Resume Next
Selection.HeaderFooter.LinkToPrevious = False
With ActiveWindow.ActivePane.View
.PreviousHeaderFooter
.NextHeaderFooter
End With
'===========================================
Is there a way that I can change my code so that the bookmark remains in the footer of the landscape and subsequent footers, please?
Thanks for any help!
The footer has a bookmark in one of the cells which will eventually hold a piece of text and will be written into that bookmark through a VBA sub-routine. I have made my bookmarks visible so that I can see what happens to them later on.
I now write some text in the document to fill a few pages and the bookmarks are still visible in the footers.
I then place my cursor at random at at paragraph mark in the text and, through VBA, I create a landscape page. I check my bookmarks and they are still there all through the document.
The next procedure is to unlink the headers and footers from the landscape page so that I can make the tables in the header and footer fill the width of the page.
It is as I unlink the header and footer of the landscape page that the bookmark disappears from it and so on through the rest of the document.
This is the code that I am using:
'sets up the new landscape page
With Selection.PageSetup
.Orientation = wdOrientLandscape
.TopMargin = CentimetersToPoints(2.2)
.BottomMargin = CentimetersToPoints(2)
.LeftMargin = oLeftMargin
.RightMargin = oRightMargin
.HeaderDistance = CentimetersToPoints(1.5)
.FooterDistance = CentimetersToPoints(0.7)
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
End With
'=========================================
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
On Error Resume Next
Selection.HeaderFooter.LinkToPrevious = False
With ActiveWindow.ActivePane.View
.PreviousHeaderFooter
.NextHeaderFooter
End With
'==============================================
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
On Error Resume Next
Selection.HeaderFooter.LinkToPrevious = False
With ActiveWindow.ActivePane.View
.PreviousHeaderFooter
.NextHeaderFooter
End With
'===========================================
'changes the widths of the tables in the header and footer
With Selection
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).PreferredWidth = CentimetersToPoints(24.15)
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Tables(1).Columns.Distrib uteWidth
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Tables(1).PreferredWidth = CentimetersToPoints(24.15)
End With
With Selection.HeaderFooter.PageNumbers
.RestartNumberingAtSection = False
End With
With ActiveWindow.ActivePane.View
.NextHeaderFooter
End With
With Selection.HeaderFooter.PageNumbers
.RestartNumberingAtSection = False
End With
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
It's when I get to this set of code that the bookmark gets erased from the footer:
'==============================================
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
On Error Resume Next
Selection.HeaderFooter.LinkToPrevious = False
With ActiveWindow.ActivePane.View
.PreviousHeaderFooter
.NextHeaderFooter
End With
'===========================================
Is there a way that I can change my code so that the bookmark remains in the footer of the landscape and subsequent footers, please?
Thanks for any help!