• Delete a page (Word 2002 SP3)

    Author
    Topic
    #445669

    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).

    Viewing 0 reply threads
    Author
    Replies
    • #1081221

      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.Paragraphs.Count).Range.Font.Size = 1
      ActiveDocument.PageSetup.TopMargin = ActiveDocument.PageSetup.TopMargin – 2

      • #1081277

        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?

        • #1081284

          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.

          • #1081286

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

            Attached is the document you requested.

            • #1081287

              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.

            • #1081288

              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?

            • #1081289

              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?

            • #1081290

              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 …

            • #1081291

              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.

            • #1081373

              Problem solved! Your are wonderful Hans!!

            • #1081307

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

              Ian

            • #1081330

              stupidme Yes, of course! Somehow, I manage to forget that solution again and again (I’m sure it has come up before). Thank you!

    Viewing 0 reply threads
    Reply To: Delete a page (Word 2002 SP3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: