Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts

    PageSetUp - This Section Only

    Hi,

    Im trying to write a macro that finds a bookmark and then resets the top margin for that particular section only.

    Whatever I do seems to set all the sections of the document to the new top margin setting and Im not sure what Im doing wrong, the code is as follows;

    Sub PageSet()

    If ActiveDocument.Bookmarks.Exists("PageSet1") = True Then
    Selection.GoTo What:=wdGoToBookmark, Name:="PageSet1"
    With Selection.PageSetup
    .TopMargin = CentimetersToPoints(1.75)
    .SectionStart = wdSectionNewPage
    End With
    End If

    End Sub

    I had thought that "wdSectionNewPage" - might have been referring to "This Section", but Im not sure and I cant find how to set the top margin to "This Section" only.

    Any help or pointers would be grately appreciated.

    Many Thanks

    Lee

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    You could get a reference to the section containing the selection as follows:

    Code:
    Activedocument.Sections(Selection.Information(wdActiveEndSectionNumber))

  3. #3
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi,

    Many thanks for your reponse, however Im not sure as to where exactly I should be putting the code you have provided as I keep getting "Invalid use of property" messages.

    Could you clarify when you have a moment maybe please?

    Many thanks

    Lee

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    Try this version using Jefferson's suggestion
    Code:
    Sub PageSet()
      Dim rng As Range
      If ActiveDocument.Bookmarks.Exists("PageSet1") = True Then
        Set rng = ActiveDocument.Bookmarks("PageSet1").Range
        With ActiveDocument.Sections(rng.Information(wdActiveEndSectionNumber)).PageSetup
          .TopMargin = CentimetersToPoints(1.75)
        End With
      End If
    End Sub
    This version doesn't change the selection object.

    The line .SectionStart = wdSectionNewPage changes the section setup to make sure the section begins on a new page. If you need that then you could put it back in.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    3 Star Lounger
    Join Date
    Aug 2006
    Location
    Gtr London, England
    Posts
    256
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi,

    Thats great, many thanks Andrew and also thanks to jscher2000, for your help.

    Best Regards
    Lee

Posting Permissions

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