Microsoft Office Tutorials and References
In Depth Information
Moving a Chart
figurE 14-3
One of the best practice items in VBA programming that I mention
throughout the book, and you will see posted in newsgroups ad nauseam, is to avoid
selecting or activating objects in your VBA code. In fact that is good advice…
most of the time. Sometimes, you need to select objects to refer reliably to them
or to manipulate them, and the preceding macro demonstrated two examples.
The ChartObject was activated to derive the actual name of the chart. Also,
the macro ended with cell A1 being selected. You could select any cell or any
object, but a cell — any cell — is the safest object to select after creating a new
embedded chart. Any code that is executed after adding a new chart will
probably not execute correctly if the chart object is still selected. The most reliable
way to deselect a chart at the end of your macro is to select a cell.
MoVing A cHArT
You can change the location of any chart, which you might be familiar with if you’ve right-clicked
a chart’s area and noticed the Move Chart menu item. The following scenarios show how to do this
with VBA.
To move a chart from a chart sheet to a worksheet, select the chart sheet programmatically and
specify the worksheet where you want the chart to be relocated. It’s usually a good idea to tell VBA
where on the worksheet you want the chart to go; otherwise, the chart is plopped down on the sheet
Search JabSto ::




Custom Search