Forum Discussion
'Calling' a function from within a Word document
- Jul 28, 2019
PMHunt1955 wrote:
I am having difficulty getting my head around how Word 'knows' that a 'block of text' is code, rather than just text of the document.
The difficulty is that Word doesn't have any way to "call" a macro automatically from the mere existence of a particular thing in the document text. The closest feature that exists is a MACROBUTTON field that contains the name of a macro, but it executes only when you double-click the field's display text.
The solution to this problem is to write a larger macro that (a) runs the mail merge and then (b) carries out the split or other functions on the resulting document. The merge main document would need to contain some "marker" to tell the macro where the merged data resides.
Another solution, probably easier to handle, would be to modify the Excel source by adding new columns to contain the split data, with unique column names that would be used only in the affected document. The other documents wouldn't even "see" the added columns.
PMHunt1955 wrote:
I am having difficulty getting my head around how Word 'knows' that a 'block of text' is code, rather than just text of the document.
The difficulty is that Word doesn't have any way to "call" a macro automatically from the mere existence of a particular thing in the document text. The closest feature that exists is a MACROBUTTON field that contains the name of a macro, but it executes only when you double-click the field's display text.
The solution to this problem is to write a larger macro that (a) runs the mail merge and then (b) carries out the split or other functions on the resulting document. The merge main document would need to contain some "marker" to tell the macro where the merged data resides.
Another solution, probably easier to handle, would be to modify the Excel source by adding new columns to contain the split data, with unique column names that would be used only in the affected document. The other documents wouldn't even "see" the added columns.
Dear Jay
Thank you very much for that insight. I was really wandering what I had missed, as I have been using Office for many years. It leads me on to wonder about what good uses are available, for VBA, in Word, but that is a question for another day. My nacent Word VBA skills are not yet at a stage where I can work out how to write a macro that calls mail merge, finds a 'marker' in the document and then performs the necessary split, so, for now, I will go down the route of adding fields to the Excel source.
If anybody at Microsoft is reading this, maybe you could look into developing a system, within Word, that does provide an ability to simply call VBA functions, during a mail merge, in the way that I have suggested in my original post.
Best regards
Philip
Bendigo, Victoria