Good bye macros. Hello merge fields!

By Brian Mulder, Updated on 20 Dec 2016
push_pin
star

Good bye macros. Hello merge fields!

Write perfect letters with SuperOffice CRM.

Are you using macros in document templates to change text formats or change SuperOffice variables in the final result of you document?

Are you tired of maintaining macro's within document templates or is the possibility to use macro's disabled by you IT?

In this article I'll give you some examples of using the merge field functionality in Microsoft Word instead of using macros.

 

First example:

Changing values like “heer”, “mevrouw”, “Herr”, “Frau” and more.

On the contact person card you have entered the value “heer” in the Mr./Mrs. Field.

When writing a letter you want to change this to “de heer”, because that’s the right way to address your letter. To get the Mr./Mrs. value in your document, choose the template variable {atmr}.

 

Before:

SuperOffice Benelux B.V.

T.a.v. heer Niels van Broekhoven

Koninginnenlaan 15

5211 WD ’s-Hertogenbosch

 

Solution:

  1. Insert a merge field on the place you want by pressing CTRL+F9
  2. Place you cursor between the brackets and type in the following values:

IF "{atmr}" = "heer" "de heer" "{atmr}" \* MERGEFORMAT

         

Explanation:

  1. We start with an IF statement because we want to change the result if it matches a value.
  2. Than we add an = symbol before the matching value
  3. Between the first "" we add the text to match with
  4. Between the second "" we add the text if the expression is true
  5. Between the third "" we add the text if the expression is false
  6. Close the IF statement with \* MERGEFORMAT

 

Result:

SuperOffice Benelux B.V.

T.a.v. de heer Niels van Broekhoven

Koninginnenlaan 15

5211 WD ’s-Hertogenbosch

 

Second example:

Using middle name like “van”, “de”, “van der”, “von” and more.

 If you want to use middle names in you letters, then you wish the final result will be something like “Niels van Broekhoven” and not “Niels Van Broekhoven” or “Niels  Broekhoven” (extra white space if middle name is empty in SuperOffice). Therefore we can use the following solution:

 

Solution:

  1. Insert a merge field on the place you want by pressing CTRL+F9
  2. Place you cursor between the brackets and type in the following values:

IF "{atmn}" = "" "" "{atmn} " \* MERGEFORMAT

               

Explanation:

  1. We start with an IF statement because we want to change the result if it matches a value.
  2. Between the first "" we add the text to match with ("" = empty)
  3. Between the second "" we add the text if the expression is true, so in this example do nothing and leave no white space behind.
  4. Between the third "" we add the text if the expression is false. We add the template variable for middle name followed by a white space. This means that if middle name is something, add the middle name and add an extra white space. Otherwise you get a result like “Niels vanBroekhoven”
  5. Close the IF statement with \* MERGEFORMAT

 

Result:

SuperOffice Benelux B.V.

T.a.v. de heer Niels van Broekhoven

Koninginnenlaan 15

5211 WD ’s-Hertogenbosch

 

Third example:

After you’ve done correcting the address format in your letter, we start with the salutation.

 

We want the salutation to be automatically changed based on if it’s “heer”, “mevrouw”, “Herr”, “Frau” and so on.

 

But what if the value is empty?

Then we want to add a text like “Geachte heer, mevrouw,” or “Sehr geehrte Damen und Herren”.

 

Solution 1:

  1. Insert a merge field on the place you want by pressing CTRL+F9
  2. Place you cursor between the brackets and type in the following values:

IF "{atmr}" = ""  "Geachte heer, mevrouw, " "Geachte {atmr}" \* MERGEFORMAT

               

Explanation:

  1. We start with an IF statement because we want to change the result if it matches a value.
  2. Than we add an = symbol before the matching value
  3. Between the first "" we add the text to match with
  4. Between the second "" we add the text if the expression is true
  5. Between the third "" we add the text if the expression is false
  6. Close the IF statement with \* MERGEFORMAT

 

Solution 2:

In Germany you use a different salutation for “Herr” and “Frau”, so we need two IF statements to resolve this problem.

  1. Insert a merge field on the place you want by pressing CTRL+F9
  2. Place you cursor between the brackets and type in the following values:

IF "{atmr}" = "" "Sehr geehrte Damen und Herren" "" \* MERGEFORMAT

               

Explanation:

  1. We start with an IF statement because we want to change the result if it matches a value.
  2. Than we add an = symbol before the matching value
  3. Between the first "" we add the text to match with ("" = empty)
  4. Between the second "" we add the text if the expression is true
  5. Between the third "" we add the text if the expression is false.

 

But this result should be “Sehr geehrte Frau” or  “Sehr geehrter Herr”

 

So we start a new IF statement between the third "" by pressing CTRL+F9 and add the values: IF "{atmr}" = "Herr" "Sehr geehrter Herr" "Sehr geehrte Frau" \* MERGEFORMAT

  1. Close the first IF statement with \* MERGEFORMAT
  2. The final result should be looking like this:

IF "{atmr}" = "" "Sehr geehrte Damen und Herren" "{ IF "{atmr}" = "Herr" "Sehr geehrter Herr" "Sehr geehrte Frau" \* MERGEFORMAT }" \* MERGEFORMAT

 

I have now shown you some examples of how to use the merge field functionality in Word to create the perfect letter by using SuperOffice template variables.

 

IMPORTANT!

If you want to update the merge fields automatically after creating the document, you need to add a visible or invisible "time or date field". You can add a date field simple by clicking the insert field function in the “Quick Parts” menu. If you don’t add this field, you need to select all text and fields by clicking CTR+A and then press F9 after the document is created.

 Quick Parts - Insert date field

TIP!

You can toggle all field codes by pressing ALT+F9. This could be usefull if you are editing the document template.

I try to implement some of this logic into a Quote-detail-template.
Is it possible to code a WHERE or IF to make a selection of ProductCategoriesKey for group/sumTotalPrice?

The goal is to exclude one categories in the sumTotal.
«TableStart:group»«GroupBy:productCategoryKey»«group/groupField» «group/sumTotalPrice»«TableEnd:group»
Frank Erik Pedersen 15 Jun 2021

I've tried to reproduce this and it works at my side.


 So if a mobile number is filled in, than show "Mobile: [mobilenumber]" else show nothing.


 Did you add a time or date mergefield somewhere in the document to update the fields automatically when created? Otherwise you have to select all text by pressing CTRL+A and than press F9 to update all merge fields in the document. 


Let me know if this works.

Brian Mulder 6 Jan 2017

Hi Marcin,


 


It depends on what you want to achieve within the quote document.


 


First of all you have the main document for you quote. This document you create like any other document in SuperOffice and will work the way I discribed. The only difference is that there's an extra merge field in the template called «QuoteDetails».




The quote detail templates are working with 2 different kind of merge fields. The first are normal document variables like "{sdat}" or "{qnum}" and the second kind are variables like «line/name».


The first type of variables are working like I already discribed, the other types are working a little bit different.


 


Example:


If you want to change the line/name value based on the result you can do something like this.


1. Press CTRL+F9


2. Type IF


3. Press CTRL+F9 again and fill in this value MERGEFIELD line/name


4. Than go back to your first statement (after { MERGEFIELD line/name } and fill in = "Nice product" "Very good product" ""


5. What will happen? If the value is "Nice product" it will automatically changed to "Very good product", otherwise keep empty.


6. The last thing fill in something between the last "" statement. This could be the mergefield line/name. So press CTRL+F9 and use MERGEFIELD line/name.


 


The final result should be like this:


{ IF { MERGEFIELD line/name } = "Nice product" "Very good product" "{ MERGEFIELD line/name}" \* MERGEFORMAT }

Brian Mulder 6 Jan 2017