Results 1 to 2 of 2

Thread: [RESOLVED] Setting border on Coverpage ONLY

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2013
    Location
    Norco, CA
    Posts
    16

    Resolved [RESOLVED] Setting border on Coverpage ONLY

    I'm using Visual Basic and i'm creating a Word doc and writing to it. I want page borders ONLY on page 1. I used the code below to create the page borders, but when I create them any page after the coverpage also has borders, which I dont want. I've read this thread(http://www.vbforums.com/showthread.p...=word+sections), but I cant figure out how to reference the second section. Any help would be appreciated.

    Thanks

    Code:
            With objApp.Selection.Sections(1).Borders(WdBorderType.wdBorderLeft)
                .LineStyle = WdLineStyle.wdLineStyleSingle
                .LineWidth = WdLineWidth.wdLineWidth050pt
                .Color = WdColor.wdColorBlack
            End With
            With objApp.Selection.Sections(1).Borders(WdBorderType.wdBorderRight)
                .LineStyle = WdLineStyle.wdLineStyleSingle
                .LineWidth = WdLineWidth.wdLineWidth050pt
                .Color = WdColor.wdColorBlack
            End With
            With objApp.Selection.Sections(1).Borders(WdBorderType.wdBorderTop)
                .LineStyle = WdLineStyle.wdLineStyleSingle
                .LineWidth = WdLineWidth.wdLineWidth050pt
                .Color = WdColor.wdColorBlack
            End With
            With objApp.Selection.Sections(1).Borders(WdBorderType.wdBorderBottom)
                .LineStyle = WdLineStyle.wdLineStyleSingle
                .LineWidth = WdLineWidth.wdLineWidth050pt
                .Color = WdColor.wdColorBlack
            End With

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Setting border on Coverpage ONLY

    put the borders in the first page only header (the header can encompass the whole page)
    same as you would a watermark

    probably better to work with the document object rather than the selection

    something like
    Code:
    With d.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Borders(wdBorderLeft)
    where d is a document
    you may also need to set the positions of the borders
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width