Search code examples
vbscriptrpaautomationanywhere

AutomationAnywhere VBScript


Hello I am trying to upload VBScript to filter out only data that has been changed. When I am using script as a Macro it works but when I am launching it via AAE it throws an

Error In Script 1024 Expected Statement.

enter image description here

Sub filtering()
    Range("H3").AutoFilter Field:=8, Criteria1:="<>"
    Range("Q3").AutoFilter Field:=17, Criteria1:="<>"
    Range("P3").AutoFilter Field:=16, Criteria1:=">=" & Range("A1").Value
    Operator:=xlAND Criteria2:="<=" & Range("A2").Value   
End Sub

Solution

  • There are 2 approaches to solve this :


    First:


    Lets include the subroutine withing within the <script> tag

    <script type="text/vbscript">
    
    Sub filtering()
        Range("H3").AutoFilter Field:=8, Criteria1:="<>"
        Range("Q3").AutoFilter Field:=17, Criteria1:="<>"
        Range("P3").AutoFilter Field:=16, Criteria1:=">=" & Range("A1").Value
        Operator:=xlAND Criteria2:="<=" & Range("A2").Value   
    End Sub
    
    </script> 
    

    Or ignore the Subroutines entirely and include the below snippet in the .vbs file in AAE

    Range("H3").AutoFilter Field:=8, Criteria1:="<>"
    Range("Q3").AutoFilter Field:=17, Criteria1:="<>"
    Range("P3").AutoFilter Field:=16, Criteria1:=">=" & Range("A1").Value
    Operator:=xlAND Criteria2:="<=" & Range("A2").Value   
    

    Second:

    You can the add the script in as an Add-in button in the form of Ribbons And in AAE you can instruct the button to click on the button by using the Object Cloning from the command library.

    For example: How the button looks like from Excel Ribbons

    enter image description here


    The Code module in the back end

    enter image description here