# VBScript - set variable to specific sheet



## HiTekRedNek (Jan 14, 2010)

Hi,

I'm trying to modify a ping script to grab a range of IP addresses from a spreadsheet (all listed IP's start on Row 2, Column 2) and append the result to the same worksheet (starting at Row 2, Column 6).

The first part of the script sets the variable.


```
set XL = CreateObject ("Excel.Application")
XL.Visible = true
XL.DisplayAlerts = false
set Sheet = XL.Workbooks.Open _
("C:\dev_offline_01112009.csv").Sheets(1)
```
 
Is this the proper way to open the csv and refer to sheet 1? During the next part of the script I want do perform a do loop that references the "Sheet" variable to go through the list of IP addresses found in Column 2.


```
do
set Cell = Sheet.Cells (2,2)
if Cell <> ""  then
call Ping
```
 
Am I on the right track?


----------



## Macropod (Jan 15, 2010)

Hi HiTekRedNek,

Sheets(1) refers to the first worksheet in the workbook, regardless of its name. If you need to refer to the worksheet named 'Sheet1', use Sheets("Sheet1").


----------

