Next, you want to create reports
that display the teams for a specific conference or all of the teams
in both conferences. By adding Visual Basic Code to your document,
you can quickly create these reports with the click of a button.
-
In the Word document,
select the location for the button.
-
In the Ribbon, click
the
Developer tab.
-
In the
Controls group, click
, and under the
ActiveX Controls heading, click the icon for the command button.
The button appears at
the location that you selected.
-
To change the text on
this button, select
Properties on the
Developer tab. The
Properties dialog box appears.
-
In the
Caption field, type
All
.
-
Select the
Font field. Click
. The
Font dialog box appears.
Specify the font size for the button text and click
OK. In this example, the font size is 7 points.
Close the
Properties dialog box. In the document, the button is
now labeled “All” and appears in the specified font.
-
Create the buttons for
the eastern and western conferences.
-
Select the location
for the button for the eastern conference and repeat steps 2–5.
The caption for this button is
Eastern Conference
.
-
Select the location
for the button for the western conference and repeat steps 2–5.
The caption for this button is
Western Conference
.
When you are finished,
you should have three buttons in your document, as shown in the following
display.
-
Double-click
All to open the Visual Basic Editor. The code for this
button is created for you.
Next, it is important
that you add a reference to the SAS Add-In 5.1 for Microsoft Office
in your Visual Basic code.
-
In the Visual Basic
Editor, select
ToolsReferences. The
References
- Project dialog box appears.
-
Select the
SAS Add-In 5.1 for Microsoft Office check box.
-
To access the automation
interface for the SAS Add-In for Microsoft Office, add the following
lines of code:
Dim sas As SASWordAddIn
Set sas = Application.COMAddIns.Item("SAS.WordAddIn").Object
-
To run the Sort Data
and List Data task when you click the
All button, add the following lines of code:
sas.Refresh ("Sort_Data") 'output: SASApp:WORK.SOCCERCLUB
sas.Refresh ("List_Data")
The first line of code
runs the Sort Data task, so that the generated Work.SoccerClub data
set will have all of the soccer teams. Now, you need the object
name (Sort_Data) for this task.
For more information,
see Determine the Object Name for the Sort Data Task.
The second line of code
runs the List Data task to create a report that includes all of the
teams.
-
In the Visual Basic
Editor, select
CommandButton2 from the drop-down
list.
The code for this button
is added to the Visual Basic editor.
-
Add the following code
for the second command button, which is the button labeled Eastern
Conference:
Dim sas As SASWordAddIn
Set sas = Application.COMAddIns.Item("SAS.WordAddIn").Object
sas.Refresh ("Sort_Data_2") 'output: SASApp:WORK.SOCCERCLUB
sas.Refresh ("List_Data")
The first line of code
runs the Sort Data task, so that the generated WORK.SOCCERCLUB data
set contains the data only for teams in the Eastern Conference. Now,
you need the object name (Sort_Data_2) for the task.
For more information,
see Determine the Object Name for the Second Sort Data Task.
The second line of code
runs the List Data task to create a report that ranks only the teams
in the Eastern Conference.
-
In the Visual Basic
Editor, select
CommandButton3 from the drop-down
list. The code for this button is added to the Visual Basic editor.
-
Add the following code
for the third command button, which is the button labeled Western
Conference:
Dim sas As SASWordAddIn
Set sas = Application.COMAddIns.Item("SAS.WordAddIn").Object
sas.Refresh ("Sort_Data_3") 'output: SASApp:WORK.SOCCERCLUB
sas.Refresh ("List_Data")
The first line of code
runs the Sort Data task, so that the generated WORK.SOCCERCLUB data
set contains the data only for teams in the Western Conference. Now,
you need the object name (Sort_Data_3) for the task.
For more information,
see Create a Temporary Data Set for the Western Conference.
The second line of code
runs the List Data task to create a report that ranks only the teams
in the Western Conference.
-
Save your changes and
close the Visual Basic Editor.
-
On the
Developer tab, deselect
Design Mode.
-
In the document, click
All. Your results should appear similar to the following
display:
When you click
Eastern Conference, your results should appear similar
to the following display:
When you click
Western Conference, your results should appear similar
to the following display: