Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
using WScript.CreateObject("Wscript.Shell | Excel Programming | |||
delete all text to the left of??? | Excel Worksheet Functions | |||
delete left 8 characters in many cells | Excel Programming | |||
Office 2003 not able to run wscript?? | Excel Programming | |||
WScript object not found (???) | Excel Programming |