Page 209 - Microsoft Office Excel 2003 Programming Inside Out
P. 209

Part 3:  The Excel Object Model
                                                       Ranges and Cells

                             The Print_Area range lets you set the range of cells using your choice of A1 notation, R1C1
                             notation, or range names. Examination of the Print_Area range properties will show you the
                             range in the style that was used to set it.








                                                                                                             Chapter 8








                             The following SelectPrint routine allows the user to choose between printing the entire sheet
                             or just the evening values from the Y2001ByMonth workbook. The Print_Area range is used
                             to inform Excel what values to print.

                             Sub SelectPrint()
                             Dim intReturn As Integer, strPrompt As String, strTitle As String
                             Dim strRange As String, objName As Name, intCounter As Integer
                                 'Call CreateNames subroutine to ensure properly named ranges
                                 'are available
                                 CreateNames
                                 'Prompt for values to print out
                                 strPrompt = "Click Yes to print only the evenint values " _
                                  & "and click No to print all values."
                                 strTitle = "Microsoft Office Excel 2003 Programming Inside Out"
                                 intReturn = MsgBox(strPrompt, vbYesNoCancel, strTitle)
                                 'Check response from user
                                 Select Case intReturn
                                    Case vbNo 'Print full chart
                                        strRange = "=" & ActiveSheet.Name & "!" & _
                                            ActiveSheet.Name & "AllValues"
                                    Case vbYes 'Print evening times only
                                        strRange = "=" & ActiveSheet.Name & "!" & _
                                            ActiveSheet.Name & "1PM:" & _
                                            ActiveSheet.Name & "8PM"
                                    Case vbCancel 'Cancel completely
                                        Exit Sub
                                 End Select

                                 'Loop through Names collection. Delete Print_Area or
                                 'Print_Titles if found.
                                 intCounter = ActiveSheet.Names.count
                                 While (intCounter > 0)
                                    If ActiveSheet.Names(intCounter).Name = ActiveSheet.Name _


                                                                                                       183
   204   205   206   207   208   209   210   211   212   213   214