See
Also > Notes on Automating
> Opening a WorkBook
> Adding a New WorkSheet
Selecting
a Specific Location on a Microsoft Excel Worksheet
This
example demonstrates how to use Automation to select a
specific range of cells in a Microsoft Excel worksheet.
This example uses the Range method to select the desired
cells.
Sub
SelectCells()
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(FileName:="c:\My
Documents\Book1.xls")
Set xlSheet = xlBook.ActiveSheet
xlApp.Visible = True
With xlSheet
' Selects cells B1:F7, then
makes cell D2 the active cell.
.Range(xlSheet.Cells(1,
2), xlSheet.Cells(7, 6)).Select
.Range("D2").Activate
' Selects an area named "MyArea"
.Range("MyArea").Select
'
Selects the last cell in the used range on the ActiveSheet
.Cells.SpecialCells(xlCellTypeLastCell).Select
'
Selects all the cells that contain formula.
.Cells.SpecialCells(xlCellTypeFormulas).Select
End
With
End
Sub
|