Good morning dear friends,
I have a problem with Chart in MS word 2010.
Task: Prepare word docx (e.g. sample.docx) with chart. Chart data are stored in text form fields, bookmarked A1 ....etc. When change fields values, chart must recalculate and refresh. No excel data editing !
Solution: I prepare sample.docx, with chart. Insert table which contains fields. On every field I call "recalculate" macro.
Problems: I cannot find my chart in ActiveDocument.InlineShapes. The collection is empty - see code below.
Sub recalculate() 'values form fields A1 = ActiveDocument.FormFields("A1").Result A2 = ActiveDocument.FormFields("A2").Result 'etc ..... others 'find chart and necessary objects Dim shp As InlineShape Dim chartCurrent As Chart Dim chartCurrentData As ChartData Dim chartWorkSheet As Excel.Worksheet For Each shp In ActiveDocument.InlineShapes If (shp.haschart) Then Set chartCurrent = shp.Chart Set chartCurrentData = shp.Chart.ChartData Set chartWorkSheet = shp.Chart.ChartData.Workbook.WorkSheets(1) End If Next shp 'Fill data with new values If Not (chartWorkSheet Is Nothing) Then chartWorkSheet.Range("B2").FormulaR1C1 = A1 'etc ......... others End If End Sub
Question: How to find my chart in document ? I'd like to set the chart object some attribute (e.g. Title = "MyChart") and find it using this attribute .
Thank you very much and nice day to all.
Marian