How to automatically create word files conditionally based on excel sheet content?

zooster

New Member
Joined
Sep 16, 2024
Messages
2
Office Version
  1. 365
Hello, I'd need to automate the creation of a word file from the content of excel rows, choosing a different template depending on the content of a specific cell.

I mean:
if K is 185 and D is lower than 31 (gender male) then open template 1a, populate certain fields of the template with A, B, C, H, etc..., then save to destination...
if K is 185 and D is higher than 41 (gender female) then open template 1b, populate certain fields of the template with A, B, C, H, etc..., then save to destination...
if K is 64 and D is lower than 31 (gender male) then open template 2a, populate certain fields of the template with A, B, C, H, etc..., then save to destination...
if K is 64 and D is higher than 41 (gender female) then open template 2b, populate certain fields of the template with A, B, C, H, etc..., then save to destination...

and so on for every row.

A macro would be preferred but I'm open to other solutions.

ABCDEFGHIJKLMNOPQRSTUVWXY
internal identifier nrname surnamebirth datepersonal identifier nr.file nr.citysupervisor namedate of meeting01/01/1900 00:0019185location of meeting00location of agreement01/01/1900 00:00Prepresentative namefiling datenotification dateother party representative
internal identifier nrname surnamebirth datepersonal identifier nr.file nr.citysupervisor namedate of meeting01/01/1900 00:001964location of meeting00location of agreement01/01/1900 00:00Prepresentative namefiling datenotification dateother party representative
 
Last edited by a moderator:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Welcome to the Board!

Typically, the best way to transfer from Excel to Word is via Mail Merge.
I would probably use filters, filter the data you need, and then complete the mail merge for each filter (to the appropriate Word merge template).
There are many videos you can find on-line that discuss this (do a Google search on "excel filter data and word mail merge").

I also came across a YouTube video on Automating Mail Merges:

Hope that helps!
 
Upvote 0
Still too complicated. I'd like an easier and more automated solution. Any code already available?
 
Upvote 0
Creating automation often is a complicated process, but usually the end result is the process created is simple for your users to use.
Whether or not there is already something out there that does something like this, I do not know. You would have to do some Google Searches.
Even if you do find something out there that does, you will probably need to modify it to suit your exact situation.

As far as getting the filters for each set of data for your 4 options in VBA code, you may be able to get a lot of that code by using the Macro Recorder and record yourself performing those steps manually. That is a great way to get snippets of code which you can use in your larger VBA project.
 
Upvote 0

Forum statistics

Threads
1,221,526
Messages
6,160,340
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top