Activating an Embedded Chart Using a Macro (71539)



The information in this article applies to:

  • Microsoft Excel for Windows 3.0
  • Microsoft Excel for Windows 3.0a
  • Microsoft Excel for Windows 4.0
  • Microsoft Excel for Windows 4.0a
  • Microsoft Excel for Windows 4.0c
  • Microsoft Excel for Windows 5.0
  • Microsoft Excel for Windows 5.0c
  • Microsoft Excel for Windows NT 5.0
  • Microsoft Excel for Windows 95

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 "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

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbcode kbmacro KB71539