dcsimg
Results 1 to 4 of 4

Thread: Removing page breaks from a Word document using Vb6

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2012
    Posts
    816

    Removing page breaks from a Word document using Vb6

    Trying to remove all page breaks from a Word document

    Code:
    Private Sub RemovePageBreaks()
        Dim Rng As Range
       oWrdAppNew.ActiveDocument.Activate
       Set Rng = ActiveDocument.Range.GoTo(What:=wdGoToPage, Name:=1)
       Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
       Rng.End = Rng.End - 2
       Rng.Collapse wdCollapseEnd
       If Asc(Rng.Characters.Last) = 12 Then Rng.Delete
       ActiveDocument.Range.InsertAfter "Ah!"
    End Sub
    The last word "Ah" verifies that I am writing to the desired document (ie it is the correct one being activated).
    Thanks all!

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2012
    Posts
    816

    Re: Removing page breaks from a Word document using Vb6

    <dup!>
    Thanks all!

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2012
    Posts
    816

    Re: Removing page breaks from a Word document using Vb6

    I've just made it work. I changed Rng.End = Rng.End -2 to Rng.End = Rng.End -1

    But I have no idea why that fixed it!
    Thanks all!

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2012
    Posts
    816

    Re: Removing page breaks from a Word document using Vb6

    Sorry. That last post turned out to be wrong. It IS -2!
    Thanks all!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width