Hi,

I am trying to create several word documents containing some text, data, and pictures, I am doing this using a loop but am running into issues where putdocx is not running in the loop, but runs fine on its own.

Here is an example of the code I am running.

version 16

global list au rf rr

foreach l of global list {
putdocx clear
putdocx begin

putdocx paragraph, style(Title)
putdocx text ("My document about `l'")

putdocx textblock begin, paramode
This is the block of text I am trying to insert.
putdocx textblock end


putdocx save "myfile_`l'.docx"
}

When I run this I get an error saying "unrecognized command 'This'" and upon tracing the program it seems the problem is that the line "putdocx textblock begin, paramode" is not running, but the previous putdocx commands ran successfully.

However, if I run the code inside the loop like so:

local l au

putdocx clear
putdocx begin

putdocx paragraph, style(Title)
putdocx text ("My document about `l'")

putdocx textblock begin, paramode
This is the block of text I am trying to insert.
putdocx textblock end


putdocx save "myfile_`l'.docx"

Then the code runs through just fine.

Does anyone have any ideas why that particular putdocx command would not execute in the loop but would run just fine outside of it?

Thanks,
Robert