It could be solved with mail merge, it might just be over the top, even if you generate the vouchers for all reservations of the day, but mail merge is of course capable to fill in placeholders and generate multiple documents, that's its main intent.
Instead of giving you code, here's the most general hint of what to do when doing something with word: Do it with word while recording a macro of it, then you can port that recorded VBA code to VFP with the following outset:
Code:
Local loWord
loWord = CreateObject("Word.Application")
loDocument = loWord.Documents.Open("C:\WordTemplates\Voucher.dotx")
* apply macro code here
loDocument.SaveAs("C:\Vouchers\xyz.pdf",17)
loWord.Quit()
Release loWord
You may even record opening the document and saving it as whatever filetype you want and get the necessary fileformat constant (here using 17 for PDF), at least the constant name you then may lookup here:
Now, just don't set the text cursor at the place to write to and manually write something, that macro recording would be quite useless, record a search&replace.
Let me make the assumption you have a doc file where name and date were filled in manually and you have ________________ within a text for that, then perhaps rather replace that with something unique like $customername$, $bookingdatebegin$, $bookingdateend$, so a search and replace can find these unique placeholders and not replace anything else in the text. Advantage: If you put in such placeholders mutliple times it's still just one search&replace per data field you want to fill in.
Obviously you need to:
1. Replace the filename of the template Voucher.dotx, this may also be a docx or dot or doc, doesn't matter.
2. Replace folders of templates and voucher output. Never just put in pure file names, Word is a separate process, it doesn't act on VFPs or your applications working directory or DEFAULT/CD path.
3. Adapt the Makro code a little. The VFP loWord object is the Application object in VBA code and loDocument is ActiveDocument. Perhaps post the code you end up and we may help with the translation.
Overall, if you do that in a loop over your data with SCAN...ENDSCAN you've done nothing less than programmed a specific mailmerge with own means, this is mainly what mail merge does, load data, for each row do a series of placement of data fields into the mail merge template and save that.
Otherwise, you have been pointed to the automation help chapter, there are whole books on the subject from Hentzenwerke, too.
Bye, Olaf.
Olaf Doschke Software Engineering