S
Scott A
I'm trying to provide writers with a macro for deleting
the last (portrait) section of a document (in situations
where they decide that they want to end the document with
a landscape section). My users are not very good with
page formatting, so I'm trying to make it as easy as
possible.
I've started with a recorded macro that goes into the
header/footer of the last section, makes them same as
previous, reformats the page to landscape layout, and then
deletes the final section and the previous section break.
The recorded macro is not toggling properly between the
header and footer, and is not working too well... I'm
wondering if anyone has recommendations for reworking the
code.
Here's what I've got so far. I've manually modified the
code in the section marked (*), which is completely
incorrect:
========================================================
Sub DeleteLast()
'
' DeleteLast Macro
' Macro recorded 18.11.2003 by scott.adams
'
'Go to last page and set view
Selection.EndKey Unit:=wdStory
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
'(*)Reset headers and footers to same as previous
With Section.Headers
HeaderFooter.LinkToPrevious = True
End With
With Section.Footer
HeaderFooter.LinkToPrevious = True
'Return to main document and set last section to
landscape
ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
Application.Browser.Target = wdBrowseSection
Application.Browser.Next
With Selection.PageSetup
.Orientation = wdOrientLandscape
End With
'Delete the last section
With ActiveDocument.Sections.Last.Range
.Delete
End With
'Remove the previous section break
Selection.TypeBackspace
Selection.Delete Unit:=wdCharacter, Count:=1
'Reset browse by object and return to top
Application.Browser.Target = wdBrowsePage
Selection.HomeKey Unit:=wdStory
End Sub
========================================================
the last (portrait) section of a document (in situations
where they decide that they want to end the document with
a landscape section). My users are not very good with
page formatting, so I'm trying to make it as easy as
possible.
I've started with a recorded macro that goes into the
header/footer of the last section, makes them same as
previous, reformats the page to landscape layout, and then
deletes the final section and the previous section break.
The recorded macro is not toggling properly between the
header and footer, and is not working too well... I'm
wondering if anyone has recommendations for reworking the
code.
Here's what I've got so far. I've manually modified the
code in the section marked (*), which is completely
incorrect:
========================================================
Sub DeleteLast()
'
' DeleteLast Macro
' Macro recorded 18.11.2003 by scott.adams
'
'Go to last page and set view
Selection.EndKey Unit:=wdStory
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or
ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
'(*)Reset headers and footers to same as previous
With Section.Headers
HeaderFooter.LinkToPrevious = True
End With
With Section.Footer
HeaderFooter.LinkToPrevious = True
'Return to main document and set last section to
landscape
ActiveWindow.ActivePane.View.SeekView =
wdSeekMainDocument
Application.Browser.Target = wdBrowseSection
Application.Browser.Next
With Selection.PageSetup
.Orientation = wdOrientLandscape
End With
'Delete the last section
With ActiveDocument.Sections.Last.Range
.Delete
End With
'Remove the previous section break
Selection.TypeBackspace
Selection.Delete Unit:=wdCharacter, Count:=1
'Reset browse by object and return to top
Application.Browser.Target = wdBrowsePage
Selection.HomeKey Unit:=wdStory
End Sub
========================================================