Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

Landscape Page Macro - Header and Footer Link Problem

$
0
0

Hi

I am using Word 2007 to write a macro which will automate inserting an A4 landscape page between two A4 portrait pages.

I have recorded the macro which achieves the outcome i require, however when i replay the macro it does not perform the same action that was recorded.

The problem occurs because the cursor is not moving to the required section header/footer in my document. As a result, it is not unlinking the required header/footer.

I have attached the macro code that was recorded and inserted comments where the code is failing (i stepped through the macro to see where it is not doing as it should). Has anyone experienced this problem and see where the macro is failing?

Thanks in advance.

Selection.InsertBreak Type:=wdSectionBreakNextPage
    Selection.InsertBreak Type:=wdSectionBreakNextPage
    ' The next line selects the correct header
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    ' The next line does not unlink the current header from the previous.
    ' It unlinks a header which is two sections further into my document
        Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
        LinkToPrevious
    ' The next line goes to the previous section footer
    WordBasic.GoToFooter
    Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
        LinkToPrevious
    ActiveWindow.ActivePane.View.PreviousHeaderFooter
        WordBasic.GoToHeader
    Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
        LinkToPrevious
    Selection.Tables(1).PreferredWidthType = wdPreferredWidthPoints
    Selection.Tables(1).PreferredWidth = CentimetersToPoints(26.5)
    WordBasic.GoToFooter
    Selection.Tables(1).PreferredWidthType = wdPreferredWidthPoints
    Selection.Tables(1).PreferredWidth = CentimetersToPoints(26.5)
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    Selection.MoveUp Unit:=wdLine, Count:=1
    With Selection.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientLandscape
        .TopMargin = CentimetersToPoints(2)
        .BottomMargin = CentimetersToPoints(1.5)
        .LeftMargin = CentimetersToPoints(2)
        .RightMargin = CentimetersToPoints(1.5)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.5)
        .FooterDistance = CentimetersToPoints(0.1)
        .PageWidth = CentimetersToPoints(29.7)
        .PageHeight = CentimetersToPoints(21)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
    End With


Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>