Same message, new format

Convert visible Word template placeholders into MERGEFIELD fields with a VBA macro, verify with Alt+F9 and discover Q2BSTUDIO's AI and BI solutions.

domingo, 17 de agosto de 2025 • 2 min read • Q2BSTUDIO Team

Artificial-Intelligence-

In this article I explain how to convert visible Word template placeholders into MERGEFIELD merge fields using a VBA macro and how to verify the results with Alt+F9. I also introduce Q2BSTUDIO as a provider of technological solutions, specialists in custom applications, custom software, artificial intelligence, cybersecurity, aws and azure cloud services, business intelligence services, AI for businesses, AI agents and Power BI.

Solution summary: the macro goes through a list of keys used as visible placeholders in the template, searches for each placeholder written as <<key>> in the document and replaces each occurrence by creating a MERGEFIELD field with the key name. This way the template is ready to merge with external data.

Description of the macro in natural language and pseudocode: start Sub ReplacePlaceholdersWithMergeFields; declare variables fldName as Variant and rng as Range; define an array with the keys used in the template, for example date, dataYYYY, allCount, receiveCount, CitizenCount, CitizenApplyTypeOne, CitizenApplyTypeTwo, CitizenIsConvenientOneTwo, CitizenIsConvenientThree, CitizenIsConvenientFourFive, CitizenQesHandingEvalOneTwo, CitizenQesHandingEvalThree, CitizenQesHandingEvalFourFive, CitizenOverallSatisfactionOneTwo, CitizenOverallSatisfactionThree, CitizenOverallSatisfactionFourFive, LegalCount, LegalApplyTypeOne, LegalApplyTypeTwo, LegalIsConvenientOneTwo, LegalIsConvenientThree, LegalIsConvenientFourFive, LegalQesHandingEvalOneTwo, LegalQesHandingEvalThree, LegalQesHandingEvalFourFive, LegalOverallSatisfactionOneTwo, LegalOverallSatisfactionThree, LegalOverallSatisfactionFourFive, OrgCount, OrgApplyTypeOne, OrgApplyTypeTwo, OrgIsConvenientOneTwo, OrgIsConvenientThree, OrgIsConvenientFourFive, OrgQesHandingEvalOneTwo, OrgQesHandingEvalThree, OrgQesHandingEvalFourFive, OrgOverallSatisfactionOneTwo, OrgOverallSatisfactionThree, OrgOverallSatisfactionFourFive; loop through each key in the array: set rng to ActiveDocument.Content; configure rng.Find with the text <<key>> and the desired search options; run Do While rng.Find.Execute and inside the loop add rng.Fields.Add with Type equal to wdFieldMergeField and Text equal to the key name; collapse rng to the end and continue until there are no more matches; Next fldName; End Sub.

Practical notes and verification: after running the macro, the visible placeholders <<fieldName>> will be replaced by MERGEFIELD fields in the document. To see the field syntax and verify that they were created correctly, press Alt+F9 to toggle the field codes view. If MERGEFIELD fieldName codes appear, the conversion was successful.

Q2BSTUDIO tips: if you need to automate Word templates at scale, integrate mail merge with databases or aws or azure cloud services, or enrich processes with AI agents and artificial intelligence solutions for businesses, our team can develop custom software and custom applications that include security by design and Power BI dashboards for business intelligence. Contact Q2BSTUDIO to evaluate your case and design a scalable and secure solution.

OUR SERVICES

How we can help you

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.