How To Use Merge With A Chart
How To Use Merge With A Chart
Prepare the chart data The data should be in a Word table, in a Word document. If you already have such a table in another application, such as Access or Excel, you should be able to simply copy and paste it into a Word document. Take care that the records are sorted in the same order as for the mail merge, and that you have at least one row of data for each record. The first column contains the ID information relating to the merge record. The second and following columns provide the data for a pie chart. The code can also produce other kinds of charts. In this case, the second column corresponds to the x-axis labels of a column chart. The remaining columns contain the data. The first row contains the legend text for the chart. Save this document and substitute its name for the Const ChartDataDoc value. Prepare the mail merge main document Set up the main merge document as a form letter, just as you always would. Use Insert/Object to insert a Microsoft Graph Chart. Choose the type of chart you want and format it the way you wish. The macro will only change the data in the data sheet. Select the chart, then over Insert/Bookmark insert a bookmark named PieChart. If you want to use a different bookmark name, you can, just remember to change the information for the Const BookmarkName. Note that the chart and bookmark can be in a table cell or a frame if you want to have text flow around the chart. Insert a normal module and a class module into the main merge document's project and copy in the corresponding code. Go into Tools/References in the Visual Basic Editor and activate the checkbox next to Microsoft Office Graph 10.0 Object Library. (Or 11.0 if you have Office 2003) Run the procedure MergeWithChart in order to execute the merge to a new document. Pay attention to the message that is displayed at the start! The updating of the MS Graph charts in the document can take a number of seconds, and Word may appear to hang. It has not, but you do have to be patient and wait until the finishing message has been displayed.