Results 1 to 6 of 6

Thread: Select text and move to a header - how to do that in VBA

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Oct 2018
    Location
    Antwerp
    Posts
    41
    Location

    Select text and move to a header - how to do that in VBA

    I want to select 3 lines of text (the 3 last lines in a document), then move this lines to the header of the document.

    My macro does not work.
    Here is the code.


    Selection.EndKey Unit:=wdStory
        Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
        Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
        Selection.Cut
        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.MoveLeft Unit:=wdCharacter, Count:=1
        ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    Last edited by Aussiebear; 12-19-2022 at 12:25 PM. Reason: Added code tags to supplied code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •