xlPie is an example of a built-in constant, also known as an enumerated constant. There are many of these throughout Excel, and they are exhaustively documented. For more information about built-in constants, see the Enumerations section of the Object Model Reference. For example, the constants for chart types are listed under "XlChartType Enumeration". You can modify the data. For example, try adding this line right after the variable declaration. VB Application.ActiveSheet.Range("a4").Value = 8 You can get input from the user, and use that input to modify the data. VB myInput = InputBox("Please type a number:") Application.ActiveSheet.Range("a5").Value = myInput Finally, add the following lines to the end of the macro. VB ActiveWorkbook.Save ActiveWorkbook.Close The complete macro should now look something like the following. VB Sub AssortedTasks() Dim myChart As ChartObject Application.ActiveSheet.Range("a4").Value = 8 myInput = InputBox("Please type a number:") Application.ActiveSheet.Range("a5").Value = myInput Set myChart = ActiveSheet.ChartObjects.Add(100, 50, 200, 200) With myChart .Chart.SetSourceData Source:=Selection .Chart.ChartType = xlPie End With ActiveWorkbook.Save ActiveWorkbook.Close End Sub Verify that cells A1:A5 are still selected, run the macro, type a number in the input box, and then click OK. The code saves and closes the workbook. Reopen the workbook and note the change to the pie chart. UserForms The previous section showed how to use a simple input box to get input from the user. In addition to the corresponding message box that displays information, VBA provides extensive capabilities that you can use to create custom dialog boxes, to code controls that are placed directly on worksheets, or to manipulate the dialog boxes that are built in to Excel. For more information about these capabilities, see in the Excel 2007 Developer Reference. This section completes this introductory look at Excel VBA by taking a quick look at UserForms.
xlPie is an example of a built-in constant, also known as an enumerated constant. There are many of these throughout Excel, and they are exhaustively documented. For more information about built-in constants, see the Enumerations section of the Object Model Reference. For example, the constants for chart types are listed under "XlChartType Enumeration". You can modify the data. For example, try adding this line right after the variable declaration. VB Application.ActiveSheet.Range("a4").Value = 8 You can get input from the user, and use that input to modify the data. VB myInput = InputBox("Please type a number:") Application.ActiveSheet.Range("a5").Value = myInput Finally, add the following lines to the end of the macro. VB ActiveWorkbook.Save ActiveWorkbook.Close The complete macro should now look something like the following. VB Sub AssortedTasks() Dim myChart As ChartObject Application.ActiveSheet.Range("a4").Value = 8 myInput = InputBox("Please type a number:") Application.ActiveSheet.Range("a5").Value = myInput Set myChart = ActiveSheet.ChartObjects.Add(100, 50, 200, 200) With myChart .Chart.SetSourceData Source:=Selection .Chart.ChartType = xlPie End With ActiveWorkbook.Save ActiveWorkbook.Close End Sub Verify that cells A1:A5 are still selected, run the macro, type a number in the input box, and then click OK. The code saves and closes the workbook. Reopen the workbook and note the change to the pie chart. UserForms The previous section showed how to use a simple input box to get input from the user. In addition to the corresponding message box that displays information, VBA provides extensive capabilities that you can use to create custom dialog boxes, to code controls that are placed directly on worksheets, or to manipulate the dialog boxes that are built in to Excel. For more information about these capabilities, see in the Excel 2007 Developer Reference. This section completes this introductory look at Excel VBA by taking a quick look at UserForms.