Tải bản đầy đủ - 0 (trang)
Example 21-3. Code in the Chart Sheet's Code Module

Example 21-3. Code in the Chart Sheet's Code Module

Tải bản đầy đủ - 0trang

bPause = Not bPause

End Sub



This code contains three procedures. The main procedure is ScrollChartTypes, which sets the

chart type and adjusts the chart's title accordingly. The procedure uses a text file, ChartTypes.txt,

that contains a list of all chart types and their names. The contents of that text file are shown in

Example 21-4. This file will need to be in the same directory as the workbook.

Example 21-4. The ChartTypes.txt File

-4169

-4151

-4120

-4102

-4101

-4100

-4098

1

4

5

15

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89



XYScatter

Radar

Doughnut

3DPie

3DLine

3DColumn

3DArea

Area

Line

Pie

Bubble

ColumnClustered

ColumnStacked

ColumnStacked100

3DColumnClustered

3DColumnStacked

3DColumnStacked100

BarClustered

BarStacked

BarStacked100

3DBarClustered

3DBarStacked

3DBarStacked100

LineStacked

LineStacked100

LineMarkers

LineMarkersStacked

LineMarkersStacked100

PieOfPie

PieExploded

3DPieExploded

BarOfPie

XYScatterSmooth

XYScatterSmoothNoMarkers

XYScatterLines

XYScatterLinesNoMarkers

AreaStacked

AreaStacked100

3DAreaStacked

3DAreaStacked100

DoughnutExploded

RadarMarkers

RadarFilled

Surface

SurfaceWireframe

SurfaceTopView

SurfaceTopViewWireframe

Bubble3DEffect

StockHLC

StockOHLC



394



90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112



StockVHLC

StockVOHLC

CylinderColClustered

CylinderColStacked

CylinderColStacked100

CylinderBarClustered

CylinderBarStacked

CylinderBarStacked100

CylinderCol

ConeColClustered

ConeColStacked

ConeColStacked100

ConeBarClustered

ConeBarStacked

ConeBarStacked100

ConeCol

PyramidColClustered

PyramidColStacked

PyramidColStacked100

PyramidBarClustered

PyramidBarStacked

PyramidBarStacked100

PyramidCol



Note the use of the On Error line in ScrollChartTypes, which resumes execution in case

we try to set the chart type to a value that is not acceptable for the particular chart.

The Delay procedure simply waits for the prescribed number of seconds. Finally, the

MouseDown event changes the state of the module level Boolean variable bPause. When the left

mouse button is clicked, scrolling is paused until the mouse button is clicked again. To stop the

procedure completely, just hit Ctrl-Break.



21.18 Example: Printing Embedded Charts

We can now implement the PrintCharts feature of our SRXUtils application. This is designed

to provide a list of the embedded charts in the active workbook, so the user can select from this list

and print the selected charts. (To print a chart sheet, use the PrintSheets utility.)

Implementing the PrintCharts utility is similar to implementing the PrintSheets and

PrintPivotTables utilities, which we did earlier in the book. At the present time, this print

utility, located in the Print.utl add-in, simply displays a message box. To implement this feature,

we want the utility to first display a dialog box, as shown in Figure 21-32.

Figure 21-32. Print Charts dialog



395



The list box contains a list of all embedded charts in the active workbook. The user can select one

or more charts and hit the Print button.

The following are the steps to create the print utility. All the action takes place in the Print.xls

workbook, so open this workbook. When the changes are finished, you will need to save Print.xls

as Print.utl as well. If Print.utl is loaded, the only way to unload it is to unload the add-in

SRXUlils.xla (if it is loaded) and close the workbook SRXUtils.xls (if it is open).



21.18.1 Create the UserForm

Create the dialog shown in Figure 21-32 in the Print.xls workbook. Name the dialog

dlgPrintCharts, change its caption to "Print Charts," and change the PrintCharts

procedure to:

Public Sub PrintCharts()

dlgPrintCharts.Show

End Sub



The dlgPrintCharts dialog has two command buttons and one list box.

21.18.1.1 List box

Place a list box on the form as in Figure 21-32. Using the Properties window, set the properties

shown in Table 21-9.

Table 21-9. Nondefault Properties of the ListBox Control

Property

Value

Name

lstCharts

TabIndex

0

MultiSelect

frmMultiSelectExtended

The MultiSelect property is set to frmMultiSelectExtended so that the user can use the

Control key to select multiple (possibly nonconsecutive) entries and the Shift key to select

multiple consecutive entries.

The TabIndex property determines not only the order in which the controls are visited as the user

hits the Tab key, but also determines which control has the initial focus. Since we want the initial

focus to be on the list box, we set its tab index to 0.

21.18.1.2 Print button

Place a command button on the form as in Figure 21-32. Using the Properties window, set the

properties shown in Table 21-10.



Name

Accelerator

Caption

TabIndex



Table 21-10. Nondefault Properties of the Print Button

Property

Value

cmdPrint

P

Print

1



21.18.1.3 Cancel button



396



Place another command button on the form as in Figure 21-32. Using the Properties window, set

the properties shown in Table 21-11.



Name

Accelerator

Caption

TabIndex

Cancel



Table 21-11. Nondefault Properties of the Cancel Button

Property

Value

cmdCancel

C

Cancel

2

True



When the Cancel property of the cmdCancel button is set to True, the button is "clicked" when

the user hits the Escape key. Thus, the Escape key will dismiss the print dialog.



21.18.2 Create the Code Behind the UserForm

Now it is time to create the code behind these controls.

21.18.2.1 The Declarations section



AM

FL

Y



The Declarations section of the UserForm should contain declarations of the module-level

variables, as shown in Example 21-5.

Example 21-5. Module-Level Declarations in the UserForm's Declarations Section



TE



Option Explicit

Dim cCharts As Integer

Dim sChartObjNames() As String

Dim sSheets() As String



21.18.2.2 Cancel button code



The Cancel button code is shown in Example 21-6.

Example 21-6. The Cancel Button's Click Event Handler

Private Sub cmdCancel_Click()

Unload Me

End Sub



21.18.2.3 Print button code

The Print button calls the main print procedure and then unloads the form, as shown in Example

21-7.

Example 21-7. The cmdPrint_Click Procedure

Private Sub cmdPrint_Click()

PrintSelectedCharts

Unload Me

End Sub



21.18.2.4 The Form's Initialize event



397 ®

Team-Fly



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Example 21-3. Code in the Chart Sheet's Code Module

Tải bản đầy đủ ngay(0 tr)

×