0 votes
1 view
in RPA by (12.8k points)

I am new to coding in VBS and all the time I am getting 1024 Expect Statement Error in my VBScript. If anyone could point me where is a mistake I would be gratefull.

Dim Path

Dim BeginDate

Dim EndDate

Path = WScript.Arguments.Item(0)

BeginDate = WScript.Arguments.Item(1)

EndDate = WScript.Arguments.Item(2)

Set objExcel = CreateObject("Excel.Application")

Set objWorkBook = objExcel.Workbooks.Open(Path)

objExcel.Visible = True

Worksheets("PO Buy Update").Range("H3").AutoFilter Field:=8, Criteria1:="<>"

Worksheets("PO Buy Update").Range("Q3").AutoFilter Field:=17, Criteria1:="<>"

Worksheets("PO Buy Update").Range("P3").AutoFilter Field:=16, Criteria1:=">=" & BeginDate, Operator:=xlAnd, Criteria2:="<=" & EndDate

Till filtering part everything goes correct. When I try to run filtering part as a Macro in Excel it works but when I am implementing it into Script it throws me an error.

closed

1 Answer

0 votes
by (29.8k points)
selected by
 
Best answer

VBScript can't handle named parameters while calling a function/method you just need to pass the values. try the code below it should work:

Dim Path
Dim BeginDate
Dim EndDate
Path = WScript.Arguments.Item(0)
BeginDate = WScript.Arguments.Item(1)
EndDate = WScript.Arguments.Item(2)
Set objExcel = CreateObject("Excel.Application")
Set objWorkBook = objExcel.Workbooks.Open(Path)
Set c=objWorkBook.Worksheets("PO Buy Update") // Attached WorkbookSheet(name) into variable and then specified which row, column is a header
objExcel.Visible = True
c.cells(3,8).AutoFilter 8, "<>"          
c.cells(3,17).AutoFilter 17, "<>"
c.cells(3,16).AutoFilter 16, ">=" & BeginDate, 1, "<=" & EndDate

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...