• Delete a line if bookmark is empty

    Author
    Topic
    #491464

    We merge a lot of documents from our SQL database using the MS Word bookmarks.

    A new requirement is to add the “Division” name to the address block. However, not all organisation use/have divisions so we wish to delete the line that contains the ClientDivision bookmark if it is empty.

    I know how to do this using the MailMerge function.

    Any ideas?

    Viewing 2 reply threads
    Author
    Replies
    • #1417049

      Any ideas on how to do this using VBA or mail merges?

      If you are doing it with code, when the Division field is non empty, insert the Division text followed by vbCr into the bookmark. Otherwise leave the bookmark empty.

    • #1417112

      A new requirement is to add the “Division” name to the address block. However, not all organisation use/have divisions so we wish to delete the line that contains the ClientDivision bookmark if it is empty.

      If this is a true mailmerge, you can suppress the “Division” line by using individual mergefields instead of the AddressBlock field.

      To suppress the empty “Division” line:
      • delete the line/paragraph break on the line before the «Division» mergefield;
      • select the «Division» mergefield and press Shift-F9. You should see { MERGEFIELD Division };
      • add the following switch to the field code by adding the b switch, thus – { MERGEFIELD Division b “¶”} or { MERGEFIELD Division b “↵”}, where the ↵ and ¶ represent real line/paragraph breaks (note that you’ll get a line/paragraph break in the mergefield);
      • press F9 to update the field; then
      • run your mailmerge.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1417211

        Paul thanks for that
        Unfortunately this is not a straight MS Word merge and we do not use mergefields. Rather it is an extraction of data from our SQL database and parsing it to named bookmarks in the Word document. The code used for extracting the data is written in XML and typically looks like this;

    • #1417231

      Phil

      You haven’t shown us how your code takes that xml information to place it onto the page. That is where the code needs to be altered. If you can show us that part of the puzzle we can suggest a way to handle it.

      If you can’t see the vba code of how the xml gets placed into the document then maybe you need a post-processing bit of code that does something along the lines of the following aircode

      Code:
      If ActiveDocument.Bookmarks("ClientDivision").Range.Text = "" then ActiveDocument.Bookmarks("ClientDivision").Range.Paragraphs(1).Delete
    Viewing 2 reply threads
    Reply To: Delete a line if bookmark is empty

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

    Your information: