How do I Create, Position, and Conditionally Set the Color of, Autoshapes in Word with VBA
Posted on 2007-10-10
I have a Word VBA macro that creates a weekly chart by inserting images (of charts) that are created by Minitab and Excel into Word tables. The order and location of each chart is the same every week.
My problem is that I have been asked to add a small Red, Yellow, Green, indicator to reflect the status of the chart. This is based on the slope of the trend line and needs to refer to a cell in Excel where the slope is calculated and stored.
I have been doing this manually by creating rectangular Autoshapes and individually formatting them with the correct color. This is inefficient and error prone.
I would like my Word macro, after inserting the images, to refer back to the cell in Excel where the slope is stored. If the slope is > 0, I would like to create a green rectangualr autoshape of a given size and put it on top of the appropriate chart, i.e, the one referred to by the Excel cell with the slope value. If the slope is less than zero, I would like it to be red, and if the zlope just happens to be zero, I would like it to be yellow. (I did not choose those criteria)
It sounds complicated. I have "slightly beyond beginner" level experience in VBA macros in Excel, but have done nothing with shapes in Word.
Nothing in the existing set of answers seems to address my problem exactly.
Can anyone provide some guidance? I would appreciate it. Thanks