Simulate the Federal Reserve Rates with the Click of a Button

Using Visual Basic code, you can add a button to the Basic Forecasting worksheet. Now, with the click of that button, you can simulate the Federal Reserve rate and update the contents of the table and the line plot.
  1. In the Ribbon, click the Developer tab.
  2. In the Controls group, click Insert, and under ActiveX Controls, select the icon for the command button.
    Insert menu with the icon for the Command button circled
  3. In the Excel worksheet, select the region where you want the button to appear.
    Adding the new Command button to the Basic Forecasting worksheet
  4. To change the text on this button, select Properties on the Developer tab. The Properties dialog box appears.
  5. In the Caption field, type Simulate.
    Updates to Caption field in the Properties dialog box
    Close the Properties dialog box. In the worksheet, the button text now reads Simulate.
    New Simulate button in the Basic Forecasting worksheet
  6. Double-click Simulate to open the Visual Basic Editor. The code for CommandButton1_Click is created for you.
    Code for the Command button as it appears in the Microsoft Visual Basic Editor
    Next, it is important that you add a reference to the SAS Add-In 5.1 for Microsoft Office in your Visual Basic code.
  7. In the Visual Basic Editor, select Toolsthen selectReferences. The References - VBAProject dialog box appears.
  8. Select the SAS Add-In 5.1 for Microsoft Office check box.
    The SAS Add-In 5.1 for Microsoft Office check box in the References dialog box
    Click OK.
  9. To access the automation interface for the SAS Add-In for Microsoft Office, enter the following lines of code:
    Dim sas As SASExcelAddIn
    Set sas = Application.COMAddIns.Item("SAS.ExcelAddIn").Object
    Two new lines of code in the Visual Basic Editor
  10. For Excel to recalculate the forecasts by using the formulas that you specified, add this code:
    Application.Calculate
  11. To refresh the line plot to reflect the recalculated forecasts, add this code:
    sas.Refresh ("Line_Plot")
    Note: The object name for your line plot might be different. To verify the object name for your line plot, select the line plot in the Basic Forecasting worksheet, and on the SAS tab, select Properties. The object name is available from the General tab in the Line Plot Properties dialog box.
    After adding these additional lines of code, the code in your Visual Basic Editor should appear similar to the following display:
    Visual Basic Editor with code for the Command button
  12. Save your changes and close the Visual Basic Editor.
  13. On the Developer tab, deselect Design Mode.
  14. In the Basic Forecasting worksheet, click Simulate. The forecasts in the table are recalculated, and the line plot is updated to show the recalculated rates.
    Recalculated Federal Reserve rates and updated line plot in the Basic Forecasting worksheet