# ERROR IN INVOKE CODE vbs code

**URL:** <https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343>\
**Category:** Academy Feedback\
**Tags:** lp-developer-adv, system, activities\
**Created:** [November 8, 2022, 5:10pm UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343 "2022-11-08T17:10:50Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![salvatore.quimi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salvatore.quimi/32/263311_2.png) [@salvatore.quimi](https://forum.uipath.com/u/salvatore.quimi)\
**Post date:** [November 8, 2022, 5:10pm UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/1 "2022-11-08T17:10:50Z")

</div>

Hi all,

I have this activity “Invoke code” with into VBS code, but when we try to run I have an error:  
In attached the code vbs and the workflow  
[Main.xaml](https://forum.uipath.com/uploads/short-url/xyZLkvEsVd9sXiudiKCiPehrsyy.xaml) (9.1 KB)

Any suggestion?

Best Regards,  
S.

---

<div class="post-metadata">

**Author:** ![Edwin\_Barahona](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/edwin_barahona/32/310876_2.png) [@Edwin\_Barahona](https://forum.uipath.com/u/Edwin_Barahona)\
**Post date:** [November 8, 2022, 9:29pm UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/2 "2022-11-08T21:29:19Z")

</div>

Hi @salvatore.quimi ,

I wasn’t able to open your file. Can you elaborate a bit more on what you’re trying to do? Also, Can you share a screenshot of the error?

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [November 8, 2022, 11:38pm UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/3 "2022-11-08T23:38:11Z")

</div>

HI,

InvokeCode activity supports not VBS but [VB.net](http://VB.net) and C#. So, can you try to use InvokeVBscript activity instead?

> **[Invoke VBScript](https://docs.uipath.com/activities/docs/invoke-vb-script)**
>
> UiPath.Core.Activities.InvokeVBScript Invokes a VBScript file and executes the commands it contains. For more information on VBScript, check the official documentation here. Properties Common DisplayName - The display name of the activity.Timeout -...

Regards,

---

<div class="post-metadata">

**Author:** ![salvatore.quimi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salvatore.quimi/32/263311_2.png) [@salvatore.quimi](https://forum.uipath.com/u/salvatore.quimi)\
**Post date:** [November 9, 2022, 10:23am UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/4 "2022-11-09T10:23:35Z")

</div>

Hi @Edwin_Barahona,

the error is this:

 ![image](https://global.discourse-cdn.com/uipath/original/4X/a/e/6/ae67b02bd31c51883110c0be2bae51d3cc0558fb.png)

And the code is:

If Not IsObject(application) Then  
SET SapGuiAuto = GetObject(“SAPGUI”)  
Set application = SapGuiAuto.GetScriptingEngine  
End If  
If Not IsObject(connection) Then  
Set connection = application.Children(0)  
End If  
If Not IsObject(session) Then  
Set session = connection.Children(0)  
End If  
If IsObject(WScript) Then  
WScript.ConnectObject session, “on”  
WScript.ConnectObject application, “on”  
End If  
session.findById(“wnd[0]”).maximize  
session.findById(“wnd[0]/tbar[0]/okcd”).text = “su01”  
session.findById(“wnd[0]”).sendVKey 0  
session.findById(“wnd[0]/usr/ctxtSUID\_ST\_BNAME-BNAME”).text = “xxxx”  
session.findById(“wnd[0]/usr/ctxtSUID\_ST\_BNAME-BNAME”).caretPosition = 6  
session.findById(“wnd[0]”).sendVKey 0  
session.findById(“wnd[0]/tbar[1]/btn[7]”).press  
session.findById(“wnd[0]/usr/tabsTABSTRIP1/tabpACTG”).select

Any suggestion?

Best Regards,  
S.

---

<div class="post-metadata">

**Author:** ![salvatore.quimi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salvatore.quimi/32/263311_2.png) [@salvatore.quimi](https://forum.uipath.com/u/salvatore.quimi)\
**Post date:** [November 9, 2022, 10:30am UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/5 "2022-11-09T10:30:48Z")

</div>

In plus the function require this one:

![image](https://global.discourse-cdn.com/uipath/original/4X/6/7/9/67979b61d6948f02afcf018323c14781db1d12cf.png)

---

<div class="post-metadata">

**Author:** ![Edwin\_Barahona](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/edwin_barahona/32/310876_2.png) [@Edwin\_Barahona](https://forum.uipath.com/u/Edwin_Barahona)\
**Post date:** [November 9, 2022, 1:28pm UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/6 "2022-11-09T13:28:50Z")

</div>

Hi @salvatore.quimi ,

I didn’t see the detail that is a VBscript (SAP script in your case), as the error says some statements are not supported by the compiler.

Instead, as @Yoichi also mentioned try one of these:

- Use Invoke VBScript

- Use **Invoke VBA** or dump the code into an excel macro and use **Run Macro** , both of these solutions require Excel Scope and enable the appropriate security settings in Excel.

> **[Invoke VBA](https://docs.uipath.com/activities/docs/invoke-vba)**
>
> UiPath.Excel.Activities.InvokeVBA Invokes a macro from an external file containing VBA code and runs it against an Excel file. This activity can run macros on any type of Excel file, such as .xls and .xlsx. Can only be used in the Excel Application...

---

<div class="post-metadata">

**Author:** ![salvatore.quimi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salvatore.quimi/32/263311_2.png) [@salvatore.quimi](https://forum.uipath.com/u/salvatore.quimi)\
**Post date:** [November 9, 2022, 2:58pm UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/7 "2022-11-09T14:58:26Z")

</div>

Thanks @Edwin_Barahona for your explanation, the Invoke VBA is for excel but in my case I would need SAPGUI.

Is there anyone who knows how to fix statements are not supported by the compiler?

@Yoichi I have already used Invoke VBS script activity but I need an activity where you can write the code as “invoke code” and not an activity that calls a file with the code inside.

Any ideas? thanks in advance

Best Regards,  
S.

---

<div class="post-metadata">

**Author:** ![Edwin\_Barahona](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/edwin_barahona/32/310876_2.png) [@Edwin\_Barahona](https://forum.uipath.com/u/Edwin_Barahona)\
**Post date:** [November 9, 2022, 3:19pm UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/8 "2022-11-09T15:19:21Z")

</div>

@salvatore.quimi, you will need to essentially convert your script from vba to [vb.net](http://vb.net), I found a few resources that may contribute to build a customized solution.

[https://help.sap.com/docs/sap\_gui\_for\_windows/b47d018c3b9b45e897faf66a6c0885a8/babdf65f4d0a4bd8b40f5ff132cb12fa.html?version=760.00](https://help.sap.com/docs/sap_gui_for_windows/b47d018c3b9b45e897faf66a6c0885a8/babdf65f4d0a4bd8b40f5ff132cb12fa.html?version=760.00)

[![](https://global.discourse-cdn.com/uipath/original/4X/1/6/6/166fe4d8c67eb51010356bba77f01b056bf23b2f.jpeg "UiPath | SAP GUI Scripting with VB.Net | How to connect to SAP with VB.Net | SAP GUI Automation") ](https://www.youtube.com/watch?v=IfFrdLD7D18)

Also, you could try using custom libraries from the marketplace

 ![image](https://global.discourse-cdn.com/uipath/original/4X/6/5/d/65d4927c4d8fabc1e4bb3bf8fda908c3f9af65b5.png)

---

<div class="post-metadata">

**Author:** ![salvatore.quimi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/salvatore.quimi/32/263311_2.png) [@salvatore.quimi](https://forum.uipath.com/u/salvatore.quimi)\
**Post date:** [November 9, 2022, 4:51pm UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/9 "2022-11-09T16:51:02Z")

</div>

Thank you for your suggestion!!!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [November 12, 2022, 4:51pm UTC](https://forum.uipath.com/t/error-in-invoke-code-vbs-code/488343/10 "2022-11-12T16:51:48Z")

</div>

Closed on November 12, 2022, 4:51pm UTC

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
