# VB Script to Delete top two rows



## Patdon67 (Feb 18, 2010)

I want to write a script to to delete the top two rows of an excel file as part of a vbs file.


----------



## jat421 (Jun 14, 2008)

something like this to open

```
Set objXL = CreateObject("Excel.Application")
 Set objWB = objXL.WorkBooks.Open("C:\Scripts\test1.xls")
 Set objWS = objXL.ActiveWorkBook.WorkSheets("test1")
```
I am not sure how to delete the row. Do a google search, you should be able to find something


----------



## Rollin_Again (Sep 4, 2003)

If the rows to be deleted will always be the same you can use this modified version of the code that was posted by Jat. Just change the bold portions to represent your path, sheet name, and rows to delete.


```
Dim objXL
Dim objWB
Dim objWS

Set objXL = CreateObject("Excel.Application")
Set objWB = objXL.Workbooks.Open("[COLOR="Red"]C:\Test\Test.xls[/COLOR]")
Set objWS = objWB.Worksheets("[COLOR="red"]Sheet1[/COLOR]")

objWS.Rows("[COLOR="red"]1:2[/COLOR]").Delete

objWB.Save

objWB.Close

objXL.Quit

Set objXL = Nothing
Set objWB = Nothing
Set objWS = Nothing
```
Regards,
Rollin


----------

