Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Jul 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Format with a particular style based on content in a merge field

    I am trying to format a merged directory as follows. If my merge field "webbold" contains the text "true" I want to format that record with "style 1". If the field contains the text "false" I want to format with "style 2" and if it contains the text "heading" I want to use a third style, "style 3". Can someone point me to a thread that might help? What is the text needed in the field code? I think I need to insert some style reference language in the field code. But I don't know enough write the code for 3 different possible results (style 1, style 2 or style 3).

  2. #2
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    Which kinds of styles are they - paragraph Styles or character Styles?
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  3. #3
    New Lounger
    Join Date
    Jul 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by macropod View Post
    Which kinds of styles are they - paragraph Styles or character Styles?
    Paragraph Styles. For example if my first merge field for a record contains the text "true" I would like that record formatted with a paragraph style that applies a specific set of tabs, font size and line spacing. (all these are contained in my "style1"). As it is now I can go through the document and do a search and replace where I find true^t (the text true followed by one tab) and replace that with style 1. The end result works but takes some time to do a search and replace for the different conditions. I hope I'm making sense here...

  4. #4
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts
    You could do that with three simple IF tests, one for each Style:
    {IF{MERGEFIELD webbold}= "true" "{MERGEFIELD webbold}¶
    "}{IF{MERGEFIELD webbold}= "heading" "{MERGEFIELD webbold}¶
    "}{IF{MERGEFIELD webbold}= "false" "{MERGEFIELD webbold}¶
    "}
    or:
    {IF«webbold»= "true" "«webbold»¶
    "}{IF«webbold»= "heading" "«webbold»¶
    "}{IF«webbold»= "false" "«webbold»¶
    "}

    where ¶ is a real paragraph break.

    Simply format each of those paragraph breaks with the requisite Style.

    Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac); you can't simply type them or copy & paste them from this message. Nor is it practical to add them via any of the standard Word dialogues. Likewise, you can't type or copy & paste the chevrons (i.e. '« »') - they're part of the actual mergefields, which you can insert from the 'Insert Merge Field' dropdown. The spaces represented in the field construction are all required.
    Last edited by macropod; 2016-03-25 at 18:24.
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  5. The Following User Says Thank You to macropod For This Useful Post:

    Charles Kenyon (2016-03-25)

Tags for this Thread

Posting Permissions

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