Vollständige Version anzeigen : How to skip empty Mail Merge files

VBA Beginer
22.11.2010, 18:05
I have a VBA macro in MS Word, which basically opens about 70 Mail Merge files one after another, and save each Mail Merge file to new normal Word document. Data source is MS Access file. Macro works fine accept one problem: Macro creates new Word document even if the query in Access is empty, so also the Mail Merge document has no data and saving the new Word document is senseless, because is only a empty form with no data and I don’t need it. Now I have to manually check all those 70 files if they are empty or not (no data) and delete them if they are. I would like that macro checks each Mail merge file if it's empty or not and skip it if it is.

When Macro opens the Mail Merge file that has no data in MS Access, an alert should be displayed:
“Word could not merge the main document with the data source because the data records were empty or no data records matched your query options”,

but I don’t see it, because I have to shut down all alerts and errors in order that Macro flows smoothly (to overwrite existing files, etc.)
Does someone know a solution for how to skip saving a Mail Merge file with no data in a Word VBA? Probably the answer is very simple, but I can’t find it. I am quite new in VBA programming. The answer in German language will be also fine.
Thanks in advance!

23.11.2010, 18:05
Hello VBA Beginner,

you might check if the document is empty before saving:

If ActiveDocument.Characters.Count > 1 Then ActiveDocument.SaveAs Filename:="C:\YourDoc.doc"

An empty document has a count of 1 character!

Gruß Ingolf