Microsoft KB Archive/71539

= Activating an Embedded Chart Using a Macro =

Article ID: 71539

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Excel 3.0 Standard Edition
 * Microsoft Excel 3.0a
 * Microsoft Excel 4.0 Standard Edition
 * Microsoft Excel 4.0a
 * Microsoft Excel 4.0c
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 5.0c
 * Microsoft Excel 5.0 Standard Edition
 * Microsoft Excel 95 Standard Edition

-



This article was previously published under Q71539



SUMMARY
You can create an embedded chart object using the chart tool on the Standard Toolbar. You must create an embedded chart in the instance of Microsoft Excel that contains the supporting data. The embedded chart is then dynamically linked to this data.

To add a legend, title, etc. to your embedded chart, you must activate the chart object. You can do this by double-clicking anywhere on the chart object. In Microsoft Excel version 5.0, when you activate an embedded chart, a hatched border appears around the chart and you can format the chart elements.

In Microsoft Excel versions 3.0 and 4.0, when you activate an embedded chart, a copy of the chart object opens in a new window. This new window displays the chart menu bar, allowing you to format the chart elements. The embedded chart on the worksheet immediately reflects all changes made to the copy in the window.

You can also activate an embedded chart object using a macro as in the following examples:

Microsoft Excel version 5.0 Visual Basic Example
' Dimension variable Dim Data As String ' Assign variable Data to selected cells Data = Selection.Address ' Create embedded chart from selected data ActiveSheet.ChartObjects.Add(82.8, 76.8, 321.6, 100.2).Select ActiveChart.ChartWizard Source:=Range(Data) ' Activate embedded chart for editing Selection.Activate Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character. For more information about Visual Basic for Applications programming style, see the &quot;Programming Style in This Manual&quot; section in the &quot;Document Conventions&quot; section of the &quot;Visual Basic User's Guide.&quot;

Microsoft Excel versions 3.0 and 4.0 Macro
  A1: =COPY A2: =CREATE.OBJECT(5,!$B$5,5,5,!$D$15,5,5) A3: =DEFINE.NAME(&quot;Temp&quot;) A4: =GET.NAME(&quot;!Temp&quot;) A5: worksheet=GET.DOCUMENT(1) A6: =UNHIDE(worksheet&amp;&quot; &quot;&amp;A2) A7: =RETURN This macro does the following:


 * 1) Copies the selected data for the chart from the worksheet
 * 2) Creates the embedded chart
 * 3) Assigns the name &quot;Temp&quot; to the chart object
 * 4) Gets the definition of the name &quot;Temp&quot;
 * 5) Assigns the name &quot;worksheet&quot; to the name of the worksheet
 * 6) Activates the chart object

Microsoft provides macro examples for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This macro is provided 'as is' and Microsoft does not guarantee that the following code can be used in all situations. Microsoft does not support modifications of that code to suit specific customer requirements.

