Page 141 - Microsoft Office Excel 2003 Programming Inside Out
P. 141
Part 3: The Excel Object Mode
The Application Object
Sub ZoomIn()
Dim intZoom As Integer
intZoom = ActiveWindow.Zoom + 50
If intZoom > 400 Then intZoom = 400
ActiveWindow.Zoom = intZoom
End Sub
Sub ZoomOut()
Dim intZoom As Integer
intZoom = ActiveWindow.Zoom - 50
If intZoom < 50 Then intZoom = 50
ActiveWindow.Zoom = intZoom
End Sub
ActiveWorkbook Property
The ActiveWorkbook property returns a Workbook object that references the currently selected
workbook. If the clipboard window is active, the ActiveWorkbook property returns Nothing.
Note The ActiveWorkbook property also returns Nothing if the only open workbook
is hidden.
The following example builds a new quarterly workbook by extracting the desired sheets out
of the annual workbook:
Sub ExtractQuarterlyFigures()
Dim szMyName As String, szQuarter As String, intCount As Integer
Dim szSheetName As String, szName As String
szMyName = ActiveWorkbook.Name
szQuarter = InputBox("Which quarter to extract (1,2,3, or 4)?", _
" Microsoft Office Excel 2003 Programming Inside Out", "1")
Application.Workbooks.Add
Select Case szQuarter
Case 1: szName = "1st Quarter.xls"
Case 2: szName = "2nd Quarter.xls"
Case 3: szName = "3rd Quarter.xls"
Case 4: szName = "4th Quarter.xls"
Case Else
MsgBox "Invalid entry ('" & szQuarter & "').", vbOKOnly + _
vbInformation, " Microsoft Office Excel 2003 Programming Inside Out"
Exit Sub
End Select
Workbooks(Workbooks.Count).SaveAs szName
For intCount = 1 To 3
Workbooks(szMyName).Activate Chapter 6
ActiveWorkbook.Sheets(intCount * Val(szQuarter)).Activate
Range("A1", ActiveCell.SpecialCells(xlLastCell)).Select
szSheetName = ActiveSheet.Name
continued
115