Newbie: Can't delete to left with WScript

D

David Wake

I'm a complete MS newbie trying to automate some processing of Excel
worksheets. I can insert values fine, but deleting doesn't work.

Here is my script, which I'm running via the Windows Script Host:


set xapp = WScript.CreateObject("Excel.Application")
xapp.Visible = True
set workbook = xapp.Workbooks.Open("Z:\home\dwake\Test.xls")
set worksheet = workbook.Worksheets("sheet1")
worksheet.Cells(1,1).Value = "Test"
worksheet.Cells(1,1).Value = "Test2"
worksheet.Range("A1:A2").Delete Shift:=xlToLeft 'this line causes problems
workbook.save()
workbook.Close(false)
xapp.Quit()


Everything runs fine if I comment out the Delete line. However, with
it I get the following error:

Script: Y:\Test.vbs
Line: 7
Char: 39
Error: Expected Statement
Code: 800A0400
Source: Microsoft VBScript compilation error.

What am I doing wrong, and how can I fix it?

Thanks!

David
 
D

Dave Peterson

Excel knows what xltoleft is, but VBS doesn't.

I opened excel, opened the VBE and went to the immediate window and typed this:
?xlToLeft

I got this back:
-4159

So your next try is:
worksheet.Range("A1:A2").Delete Shift:=-4159

or
worksheet.Range("A1:A2").Delete -4159
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VB Script to remove row 1

Top