Activating an Embedded Chart Using a Macro

ID: Q71539


The information in this article applies to:
  • Microsoft Excel for Windows, versions 3.x, 4.x, 5.0, 5.0c
  • Microsoft Excel for Windows NT, version 5.0
  • Microsoft Excel for Windows 95, version 7.0


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 "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide."

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("Temp")
   A4: =GET.NAME("!Temp")
   A5: worksheet=GET.DOCUMENT(1)
   A6: =UNHIDE(worksheet&" "&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 "Temp" to the chart object


  4. Gets the definition of the name "Temp"


  5. Assigns the name "worksheet" 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.


REFERENCES

"User's Guide," version 4.0, page 394-399, 435

"User's Guide," version 3.0, page 325, 391-394

"Function Reference," version 4.0, pages 65-66, 77-79, 196, 201, 441

"Function Reference," version 3.0, pages 36, 40, 107, 111, 241

Additional query words: 3.0 3.00 4.0 4.00 5.0 \* Rewrite: tonyaw 3/94 xl7 TechRevBy: garymu

Keywords : kbcode kbmacro
Version : WINDOWS:3.x,4.x,5.0,5.0c,7.0; winnt:5.0
Platform : WINDOWS winnt
Issue type :


Last Reviewed: October 19, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.