• Header Disconnect & Delete Text (2000)

    • This topic has 4 replies, 2 voices, and was last updated 21 years ago.
    Author
    Topic
    #405126

    I have recorded a macro to insert a section break and disconnect the header from previous. I tried to get it to delete the text in the now disconnected section but it doesn’t seem to work. I don’t know VB so any suggestions would be gratefully recieved.

    Sub aaa()

    ‘ aaa Macro
    ‘ Macro recorded 19/05/2004 by HettyB

    Selection.InsertBreak Type:=wdSectionBreakNextPage
    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
    ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
    Selection.HeaderFooter.LinkToPrevious = Not Selection.HeaderFooter. _
    LinkToPrevious
    Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
    Selection.Delete Unit:=wdCharacter, Count:=1
    ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    End Sub

    Viewing 1 reply thread
    Author
    Replies
    • #829379

      Recorded macros can be very useful, but in this case, the generated code is not only convoluted, but doesn’t do what you want. It deletes the first word in the header of the section before the break. Try this instead:

      Sub aaa()
      Selection.InsertBreak Type:=wdSectionBreakNextPage
      With Selection.Sections(1).Headers(wdHeaderFooterPrimary)
      .LinkToPrevious = False
      .Range.Delete
      End With
      End Sub

      If you also have a first-page header and/or even-page header that is different from the standard one, you must treat those separately.

      • #829401

        I worship at your feet. starstruck

        This works great. We don’t encourage different first page headers/footers. No one ever uses them properly and can’t figure out what is going wrong when someone does.

      • #829402

        I worship at your feet. starstruck

        This works great. We don’t encourage different first page headers/footers. No one ever uses them properly and can’t figure out what is going wrong when someone does.

    • #829380

      Recorded macros can be very useful, but in this case, the generated code is not only convoluted, but doesn’t do what you want. It deletes the first word in the header of the section before the break. Try this instead:

      Sub aaa()
      Selection.InsertBreak Type:=wdSectionBreakNextPage
      With Selection.Sections(1).Headers(wdHeaderFooterPrimary)
      .LinkToPrevious = False
      .Range.Delete
      End With
      End Sub

      If you also have a first-page header and/or even-page header that is different from the standard one, you must treat those separately.

    Viewing 1 reply thread
    Reply To: Header Disconnect & Delete Text (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: