Share via

VBA bookmark value

Anonymous
2018-08-10T14:28:04+00:00

I have a macro that i'd like to run after a mailmerge. I have several bookmarks with text values based on merge fields. I'd like to create a macro that runs based on what that bookmark was set to be.

if my bookmark name is "reusable" and the mergefield is such that after the merge, reusable = "yes" for some of the merge documents and "no" for others, how can I create code to run a macro that checks each merge document created and if the bookmark named reusable = "yes", then add some text to that specific merge document but if = "no", don't do anything at all.

Thanks so much!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2018-08-11T00:45:47+00:00

    Bookmarks will not survive the execution of the merge operation.

    However, it sounds like at the location of the bookmarks in the mail merge main document, you could use an If...then...Else field construction that checks the result of the particular merge field and inserts the appropriate text, depending upon whether the result is Yes or No.

    If you want to execute the merge to individual documents, use that facility on my Merge Tools Add-in that is contained in the MERGE TOOLS ADD-IN.zip file that you can download from the following page of my One Drive:

    http://bit.ly/1hduSCB

    Extract the files from the archive and read the:

    “READ ME – Setting up and using the Merge Tools Add-in.docx

    to see how to install and use the various tools.  Using those tools, it is possible to perform the following types of merge that cannot be done with Mail Merge “out-of-the-box”:

    ●    Merge to e-mail messages either with or without attachments, with the documents created by the merge being sent as either Word or PDF attachments or as the body of the e-mail message.

    ●    Merge to individual documents in either Word or PDF format with the filenames being supplied by the data in one of the fields in the data source

    ●    Many to One type merges, which can be used for creating documents such as invoices where there are multiple records in the data source that have common data in one of the fields

    ●    Merging to a document that will include a chart that is unique to each record in the data source

    ●    Merging a document with Content Controls

    ●    Merging a document that contains Legacy FormFields

    ●    Duplex Merges

    ●    Merging to a printer that will collate and staple the output created from each record in the data source.

    The requirements for using the system are:

    ●    The mail merge main document must be of the Letters type, though that does not mean that the output cannot be sent as an e-mail message where relevant.

    ●    For the Many To One, Merge with Attachments and Merge to Individual Docs utilities, the data source may be either a table or query in an Access database, or in the form of an Excel worksheet and that worksheet must be the first sheet in the Excel workbook. If the data is on some other sheet, you can easily move that sheet so that it is the first sheet in the workbook by clicking on the sheet tab and dragging it to the left.  For the Chart Merge utility, see the Mail Merging with Charts document that is included in the Merge Tools Add-in Zip file for additional requirements for the data source for use with that utility

    ●    For a data source in the form of an Excel worksheet, the field names must be in the first row of the worksheet and there must be a field name in all of the cells in that row that are within the range of columns that contain the data.

    ●    For both types of data source, the field names must contain only alphanumeric characters (No @,#,$,%,&,(,), etc) and the field names must not start with a numeric character (0-9). The number of characters in the field names, including spaces, must not be more than 40

    .

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Anonymous
    2018-08-11T00:36:33+00:00

    it's difficult for me to distinguish when the same principles are to be used so I didnt realize they were the same question. but thank you for your feedback.

    Was this answer helpful?

    0 comments No comments
  3. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2018-08-11T00:34:33+00:00

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2018-08-10T14:33:36+00:00

    A bookmark is a Range and a Range has a Text property, so you check the value of Range.Text with something like.

    If Document.Bookmark("Name").Range.Text = "Yes" Then do something.

    Was this answer helpful?

    0 comments No comments