page break deletes text

Posted on Jan 08, 2009 under xn--zqqs84h3is.com | edit
  • When I insert a page break programmatically it deletes all the preceeding text.
    mobjWordApp.Selection.EndKey Unit:=wdStory
    mobjWordApp.ActiveDocument.Content.InsertBreak (wdPageBreak)

    WHY? :saywhat:

    I'm creating a Word document (based on a template) via Access and programmatically replacing bookmarks with appropriate data.

    What I'm trying to do is a kind of mail-merge type thing - DIY. In the template I've got two bookmarks (for test purposes).
    1. Copy all of document
    2. Fill bookmarks
    3. go to end of document
    4. insert page break
    5. paste clipboard
    and then repeat from 2. until all records in Access have been iterated through.

    So anyway, why is it doing this?

    I can do it manually i.e. Ctrl-End, Ctrl-Enter (or Insert > Page Break)

    any ideas?

    thanks :)


  • thanks for the tip Dreamboat. :friendship:

    I applied the get-the-macro-to-tell-you-what-Word-is-doing idea and established that my real problem was: the code I was using for step '5' - pasting from the clipboard:
    mobjWordApp.ActiveDocument.Content.Paste

    the macro code, which works is:
    mobjWordApp.Selection.PasteAndFormat (wdPasteDefault)

    so there we are. its working. I'm quite chuffed with myself. I just ran it from access on a sorted form and it produced 304 pages of letters. cool. :)


  • When I record the macro, this is the code I get.

    Selection.EndKey Unit:=wdStory
    Selection.InsertBreak Type:=wdPageBreak







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about page break deletes text , Please add it free.