Results 1 to 13 of 13
  1. #1
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    269
    Thanks
    32
    Thanked 0 Times in 0 Posts

    Delete a page (Word 2002 SP3)

    I would be very grateful if someone could please help me with the VBA code to delete the second (and final) page of a document.

    There is some VBA code that inserts a table of 8 cells covering the first page of the document. This creates a blank second page that I am simply unable to delete (going to the end of the document and doing a backspace does not delete the page, due to the table covering the first page, which is why I thought that maybe VBA code may work).

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

    Re: Delete a page (Word 2002 SP3)

    In most cases, it is sufficient to set the font size of the last paragraph in the document (below the table) to 1 point. If the table fits exactly on the page, you may have to decrease the page margins too. The following lines should get rid of the last page in all circumstances:

    ActiveDocument.Paragraphs(ActiveDocument.Paragraph s.Count).Range.Font.Size = 1
    ActiveDocument.PageSetup.TopMargin = ActiveDocument.PageSetup.TopMargin - 2

  3. #3
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    269
    Thanks
    32
    Thanked 0 Times in 0 Posts

    Re: Delete a page (Word 2002 SP3)

    Hi Hans

    Thanks for your prompt response - I really appreciate it.

    Unfortunately the technique does not work. Reducing the font size of the last paragraph below the table that occupies all of the first page to 1 point is not enough to eliminate the blank second page, while decreasing the top margin disrupts the 8 evenly spaced cells of the table on the first page, so now I get two sets of 4 cells in the middle of the 2 pages.

    Do you by any chance have another suggestion?

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

    Re: Delete a page (Word 2002 SP3)

    No. Word documents always have a paragraph mark at the end. If the document ends with a table, that last paragraph mark is below the table. Usually, reducing the font size of the last paragraph mark to 1 point is sufficient to keep it on the same page as the table, and otherwise adjusting the page margins slightly will do the job. I don't understand why you get 4 cells on each page.
    Could you attach a copy of the document with just the table? You can remove all text from the document.

  5. #5
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    269
    Thanks
    32
    Thanked 0 Times in 0 Posts

    Re: Delete a page (Word 2002 SP3)

    Thank you very much Hans - I really appreciate your help.

    Attached is the document you requested.
    Attached Files Attached Files

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

    Re: Delete a page (Word 2002 SP3)

    Thanks, now I understand what is happening. Your top and bottom margins are set at 0, and the table takes up the entire height of the page:
    A landscape A4 page is 21.0 cm high, and you have two rows of exactly 10.5 cm high, together 2 * 10.5 = 21.0 cm.
    This means that there is no way at all to fit the last paragraph mark on the first page.

    If you really need the rows to be 10.5 cm high, you'll have to live with the blank page. You can specify that you want to skip it when printing the document.
    If you prefer to have a one-page document, you will have to decrease the height of the rows slightly, for example to 10.45 cm, to make space for the last paragraph mark (which has to be set to 1 point font size).
    See the attached version.
    Attached Files Attached Files

  7. #7
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    269
    Thanks
    32
    Thanked 0 Times in 0 Posts

    Re: Delete a page (Word 2002 SP3)

    Hans, I don't need the rows to be 10.5cm high, so your suggestion to reduce them to 10.45 seems fine if I end up with a single page. The attached file however seems to still produce two pages when I run the code. Am I doing something wrong?

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

    Re: Delete a page (Word 2002 SP3)

    Decreasing the row height means that you don't need to adjust the top margin, so you should *not* use the line

    ActiveDocument.PageSetup.TopMargin = ActiveDocument.PageSetup.TopMargin - 2

    Simply delete this line. Or do you mean other code? If so, which code?

  9. #9
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    269
    Thanks
    32
    Thanked 0 Times in 0 Posts

    Re: Delete a page (Word 2002 SP3)

    I used the VBA code (behind the OK button on the form) in the file you sent back, but it still produced the same two page document as it did originally. Clearly I am doing something wrong ...

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

    Re: Delete a page (Word 2002 SP3)

    There is no form in the document I sent back, nor any VBA code - it must be in one of your own templates, perhaps in your Normal.dot.

  11. #11
    Bronze Lounger IanWilson's Avatar
    Join Date
    Dec 2000
    Location
    Bristol, United Kingdom
    Posts
    1,523
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Delete a page (Word 2002 SP3)

    Isn't it possible to format the final paragraph as hidden text?

    Ian

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

    Re: Delete a page (Word 2002 SP3)

    <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30> Yes, of course! Somehow, I manage to forget that solution again and again (I'm sure it has come up before). Thank you!

  13. #13
    3 Star Lounger
    Join Date
    May 2002
    Location
    Melbourne, Australia
    Posts
    269
    Thanks
    32
    Thanked 0 Times in 0 Posts

    Re: Delete a page (Word 2002 SP3)

    Problem solved! Your are wonderful Hans!!

Posting Permissions

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