问题
I have a list of emails and some are for company names and others have first name last name. If I include the greetings line for "hello first_name last_name" it works but I want it to say "hello company_name" if there is no first name. Is there a way to do this?
回答1:
To place this logic into your mail merge I suggest forgoing the Greeting Line and instead nesting Merge Field Codes inside a Word If, Then, Else statement. Field Codes are invisible markers and logic that Word replaces with text when needed.
Important Note: Do not copy and paste the below code into your mail merge main document. The curly braces { }
in the code are generated by typing CTRL-F9 in your Word document. Generating these braces in this manner tells Word that this will be a Field Code. As such you will need to type the below code using CTRL-F9 to generate these braces when needed.
Important Note 2: Field Codes are invisible unless the document is toggled to display them. ALT-F9 will toggle your document to hide field codes (so you can test the merge) or display them (so you can edit the code).
Word's IF
statement, which is itself placed within Field Code braces, has the syntax If test is true, then true, else false. Word uses spaces to separate the test, true, and false sections. It also requires that the true and false outcomes are enclosed in quotation marks. All Field Codes are enclosed in curly braces (CTRL-F9).
Place the following code between the opening text (for example, "Dear") and closing punctuation (comma or colon).
{ IF { MERGEFIELD Last_Name } = "" "{ MERGEFIELD Company_Name }" "{ MERGEFIELD First_Name } { MERGEFIELD Last_Name }"}
来源:https://stackoverflow.com/questions/40682295/microsoft-office-word-2016-mail-merge-custom-invalid-recipement-for-greeting-lin