Results 1 to 7 of 7
  1. #1
    5 Star Lounger
    Join Date
    Jul 2003
    Location
    USA
    Posts
    728
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Copy a page and its Setup info (Word 97/SR2)

    Good morning -

    Am trying to figure out how to create Code that copies a page AND its settings into a new window. To copy the page, I use
    Sub PageSelect()

    Selection.Bookmarks("page").Select
    Selection.Copy
    End Sub
    but would like to have the page setup info also carry over. I tried copying the section break after the text, didn

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy a page and its Setup info (Word 97/SR2)

    Change the code to set the page layout as follows:

    - Change <code>Orientation</code> to <code>.Orientation</code>
    - Remove the second End With, there is no corresponding With (at least not in the code you posted).

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Copy a page and its Setup info (Word 97/SR2)

    Hi acerfmayer,

    It looks like you're defining the page dimensions in your active document, rather than copying them.

    If your source document's page setup is consistent with its template and the target document's setup is to be the same, creating the target document from the same template would be simplest.
    To make sure the margins and header/footers are the same in the source.doc and a new target.doc, use something like this:

    Documents.add Template:=ActiveDocument.FullName, NewTemplate:=False, DocumentType:=0


    To simply copy across page dimensions to a section in an existing target document, copy the source document's page dimensions using something like:

    With ActiveDocument.PageSetup
    oLeftMargin = .LeftMargin
    oRightMargin = .RightMargin
    oGutter = .Gutter
    oPageWidth = .PageWidth
    oTopMargin = .TopMargin
    oBottomMargin = .BottomMargin
    oPageHeight = .PageHeight
    End With

    Then activate target document it and use something like:

    With ActiveDocument.PageSetup
    .LeftMargin = oLeftMargin
    .RightMargin = oRightMargin
    .Gutter = oGutter
    .PageWidth = oPageWidth
    .TopMargin = oTopMargin
    .BottomMargin = oBottomMargin
    .PageHeight = oPageHeight
    End With

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    5 Star Lounger
    Join Date
    Jul 2003
    Location
    USA
    Posts
    728
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Re: Copy a page and its Setup info (Word 97/SR2)

    Thank you, Hans and Macropod. Very much.

    ACM

  5. #5
    5 Star Lounger
    Join Date
    Jul 2003
    Location
    USA
    Posts
    728
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Re: Copy a page and its Setup info (Word 97/SR2)

    Hans

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Copy a page and its Setup info (Word 97/SR2)

    Your code sets the page setup in the source (the text to be copied), not in the target. You will need something like macropod's code, with Selection.PageSetup instead of ActiveDocument.PageSetup:

    ' Module-level variables
    Dim oOrientation As WdOrientation
    Dim oLeftMargin As Single
    Dim oRightMargin As Single
    Dim oGutter As Single
    Dim oPageWidth As Single
    Dim oTopMargin As Single
    Dim oBottomMargin As Single
    Dim oPageHeight As Single
    Dim oHeaderDistance As Single
    Dim oFooterDistance As Single

    ' Position insertion point in page to be copied, then run this.
    Sub CopyPage()
    With Selection.PageSetup
    oOrientation = .Orientation
    oLeftMargin = .LeftMargin
    oRightMargin = .RightMargin
    oGutter = .Gutter
    oPageWidth = .PageWidth
    oTopMargin = .TopMargin
    oBottomMargin = .BottomMargin
    oPageHeight = .PageHeight
    oHeaderDistance = .HeaderDistance
    oFooterDistance = .FooterDistance
    End With
    Selection.Bookmarks("page").Range.Copy
    End Sub

    ' Position insertion point where page should be pasted, then run this.
    Sub PastePage()
    Selection.InsertBreak wdSectionBreakNextPage
    Selection.Paste
    Selection.MoveLeft
    With Selection.PageSetup
    .Orientation = oOrientation
    .LeftMargin = oLeftMargin
    .RightMargin = oRightMargin
    .Gutter = oGutter
    .PageWidth = oPageWidth
    .TopMargin = oTopMargin
    .BottomMargin = oBottomMargin
    .PageHeight = oPageHeight
    .HeaderDistance = oHeaderDistance
    .FooterDistance = oFooterDistance
    End With
    End Sub

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Copy a page and its Setup info (Word 97/SR2)

    The Page Setup settings are stored in the invisible section break at the end of your page. Unless you insert a manual section break and copy that over, copy-and-paste will not bring over those settings. The macros above, which capture the page setup settings in your source document so you can apply them to your destination document, seem more complicated now, but when you consider the pain and suffering than an unnecessary section break can cause, and the unhappiness that can result from deleting it, you'll probably find it worthwhile to use a macro. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

Posting Permissions

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