![]() |
Newbie: Can't delete to left with WScript
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 |
Newbie: Can't delete to left with WScript
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 David Wake wrote: 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 -- Dave Peterson |
All times are GMT +1. The time now is 01:31 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com