PDA

View Full Version : Running vba code for each record in a mail merged document



Agent Smith
06-06-2019, 04:56 AM
I thought I would post this separately as it's a different question.

I have a mail merged letter. I can run some vba code when the document opens and this alters some aspects of the initial opened document. As I click through the different records the original info comes back replacing the vba edited content.

Is there a way to get the vba code to run each time I click on a different record?

gmayor
06-06-2019, 05:22 AM
The short answer is no, but you could split the merge (or the merged document) and run a macro on the individual documents.
https://www.gmayor.com/individual_merge_letters.htm, https://www.gmayor.com/MergeAndSplit.htm and https://www.gmayor.com/ManyToOne.htm all provide an option to merge to separate documents and run a macro. The macro does however have to conform to a particular format described on the web pages and in the help files.

Agent Smith
06-06-2019, 11:02 AM
Could I add a macro button to print and just add the image changing code to that?

Edit: seems I can create a macro button and link to the quick access toolbar.

gmayor
06-06-2019, 08:07 PM
Why do you need to change images? Why not merge the images - https://www.gmayor.com/mail_merge_graphics.htm and https://www.gmayor.com/mail_merge_graphics_addin.htm ?