# Declaration in Invoke Code

**URL:** <https://forum.uipath.com/t/declaration-in-invoke-code/206379>\
**Category:** Academy Feedback\
**Tags:** excel, system, activities\
**Created:** [27.Март.2020 09:48:05 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379 "2020-03-27T09:48:05Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![trunghai](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/trunghai/32/177411_2.png) [@trunghai](https://forum.uipath.com/u/trunghai)\
**Post date:** [27.Март.2020 09:48:05 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/1 "2020-03-27T09:48:05Z")

</div>

Hi Everyone.

I have a VBA code as below. I want to add this into the Invoke Activity.

How to declare arguments in the Invoke Activity ?

I dont know how to create arguments for this code work normally in the invoke code activity.

Thanks in advance!

Dim strTest As String  
Dim strLen As Integer  
strTest = “INV”  
strLen = Len(strTest)  
For Each Cell In Sheet6.Range(“E5:U23”)  
If InStr(Cell, strTest) \> 0 Then  
Cell.Characters(InStr(Cell, strTest), strLen).Font.Color = vbRed  
Cell.Characters(InStr(Cell, strTest), strLen).Font.Bold = True  
End If  
Next

 ![pic](https://global.discourse-cdn.com/uipath/original/3X/4/e/4eb45d48a85aebf2ae40ce60aa21042debcd1319.jpeg)

---

<div class="post-metadata">

**Author:** ![hasib08](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/hasib08/32/73642_2.png) [@hasib08](https://forum.uipath.com/u/hasib08)\
**Post date:** [27.Март.2020 09:51:13 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/2 "2020-03-27T09:51:13Z")

</div>

The variable which you are using in code i.e. “INV”  
Pass arguments for them

Thanks  
@trunghai

---

<div class="post-metadata">

**Author:** ![Manish540](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/manish540/32/356167_2.png) [@Manish540](https://forum.uipath.com/u/Manish540)\
**Post date:** [27.Март.2020 09:54:23 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/3 "2020-03-27T09:54:23Z")

</div>

What all variables you want to pass inside the invoke code ? @trunghai

---

<div class="post-metadata">

**Author:** ![trunghai](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/trunghai/32/177411_2.png) [@trunghai](https://forum.uipath.com/u/trunghai)\
**Post date:** [27.Март.2020 09:56:06 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/4 "2020-03-27T09:56:06Z")

</div>

Hi @Manish540

Yes.!

I want to declare them in the arguments table as below. But i’m not clearly understand this . So, i need one example to study.

 ![1](https://global.discourse-cdn.com/uipath/original/3X/2/9/29bd1911de76a7824c46dd5ca11b319084b84e90.jpeg)

---

<div class="post-metadata">

**Author:** ![Manish540](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/manish540/32/356167_2.png) [@Manish540](https://forum.uipath.com/u/Manish540)\
**Post date:** [27.Март.2020 10:01:44 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/5 "2020-03-27T10:01:44Z")

</div>

Like if you want to pass cell range then for example,  
Go to edit arguments, create argument as below screenshot,

 ![EditArguments](https://global.discourse-cdn.com/uipath/original/3X/3/1/31cd5aa43ef0f56bf1d354272c5cf2cf60177b32.png)  
Then inside the code use CellRange as,  
For Each Cell In Sheet6.Range(CellRange).

---

<div class="post-metadata">

**Author:** ![trunghai](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/trunghai/32/177411_2.png) [@trunghai](https://forum.uipath.com/u/trunghai)\
**Post date:** [27.Март.2020 10:07:11 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/6 "2020-03-27T10:07:11Z")

</div>

Hi Bro @Manish540

I have create argument as your guide.

But it has something wrong.

 ![1](https://global.discourse-cdn.com/uipath/original/3X/0/f/0ff91cabbcc5bd2af5c1d2bceccc6c3154798d46.png)

---

<div class="post-metadata">

**Author:** ![Manish540](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/manish540/32/356167_2.png) [@Manish540](https://forum.uipath.com/u/Manish540)\
**Post date:** [27.Март.2020 10:10:20 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/7 "2020-03-27T10:10:20Z")

</div>

What is the variable type of cellRange it should be string type??  
I tried in my machine its not getting that error.

---

<div class="post-metadata">

**Author:** ![Cristian\_Bardas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/cristian_bardas/32/60932_2.png) [@Cristian\_Bardas](https://forum.uipath.com/u/Cristian_Bardas)\
**Post date:** [27.Март.2020 10:22:02 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/8 "2020-03-27T10:22:02Z")

</div>

First, your VBA code should accept input arguments:

**Public Function Test(strTest as String) as String**

Dim strLen As Integer  
strTest = “INV”  
strLen = Len(strTest)  
For Each Cell In Sheet6.Range(“E5:U23”)  
If InStr(Cell, strTest) \> 0 Then  
Cell.Characters(InStr(Cell, strTest), strLen).Font.Color = vbRed  
Cell.Characters(InStr(Cell, strTest), strLen).Font.Bold = True  
End If  
Next  
End function

Then parse the parameters to the VBA code as follows: ![image](https://global.discourse-cdn.com/uipath/original/3X/c/1/c19defcc3a048802c755cee8d9ad4e9695e4b267.png)

---

<div class="post-metadata">

**Author:** ![trunghai](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/trunghai/32/177411_2.png) [@trunghai](https://forum.uipath.com/u/trunghai)\
**Post date:** [30.Март.2020 02:31:01 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/9 "2020-03-30T02:31:01Z")

</div>

Hi Bro @Manish540

Sorry for late reply.

The purpose of my VBA code to find special string “INV” and highlight them in cell by cell within range “E5:U23”

---

<div class="post-metadata">

**Author:** ![trunghai](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/trunghai/32/177411_2.png) [@trunghai](https://forum.uipath.com/u/trunghai)\
**Post date:** [30.Март.2020 02:52:16 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/10 "2020-03-30T02:52:16Z")

</div>

Hi Bro @Cristian_Bardas

Thanks you. Could you pls check my xlsx file ?

I want to use my VBA code as below to find and highlight special text “INV” within range “A2:A4” .

Pls try to create your xaml file by using invoke code activity inside .

Thanks you so much!

Dim strTest As String  
Dim strLen As Integer  
strTest = “INV”  
strLen = Len(strTest)  
For Each Cell In Sheet1.Range(“A2:A4”)  
If InStr(Cell, strTest) \> 0 Then  
Cell.Characters(InStr(Cell, strTest), strLen).Font.Color = vbRed  
Cell.Characters(InStr(Cell, strTest), strLen).Font.Bold = True  
End If  
Next

[file.xlsx](https://forum.uipath.com/uploads/short-url/rjVgWhiI3eG7TgkxIpMBRPG2JUd.xlsx) (8.0 KB)

---

<div class="post-metadata">

**Author:** ![Cristian\_Bardas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/cristian_bardas/32/60932_2.png) [@Cristian\_Bardas](https://forum.uipath.com/u/Cristian_Bardas)\
**Post date:** [30.Март.2020 05:52:37 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/11 "2020-03-30T05:52:37Z")

</div>

Here you go, it should be what you need.

[ExcelVBA.zip](https://forum.uipath.com/uploads/short-url/gl5RJ6vXtg63ABhJfaqDZkiFuUz.zip) (24.4 KB)

---

<div class="post-metadata">

**Author:** ![trunghai](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/trunghai/32/177411_2.png) [@trunghai](https://forum.uipath.com/u/trunghai)\
**Post date:** [30.Март.2020 05:57:20 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/12 "2020-03-30T05:57:20Z")

</div>

> [@trunghai](#):
>
> Dim strTest As String  
> Dim strLen As Integer  
> strTest = “INV”  
> strLen = Len(strTest)  
> For Each Cell In Sheet1.Range(“A2:A4”)  
> If InStr(Cell, strTest) \> 0 Then  
> Cell.Characters(InStr(Cell, strTest), strLen).Font.Color = vbRed  
> Cell.Characters(InStr(Cell, strTest), strLen).Font.Bold = True  
> End If  
> Next

Hi Bro @Cristian_Bardas

Thanks you Bro. But i known how to use invoke VBA ( txt file ).

I want to add VBA code into the invoke code activity with declare arguments.

---

<div class="post-metadata">

**Author:** ![Cristian\_Bardas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/cristian_bardas/32/60932_2.png) [@Cristian\_Bardas](https://forum.uipath.com/u/Cristian_Bardas)\
**Post date:** [30.Март.2020 05:59:04 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/13 "2020-03-30T05:59:04Z")

</div>

Check the file, the string to be searched for is added as a parameter. Isn’t this what you need?

---

<div class="post-metadata">

**Author:** ![trunghai](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/trunghai/32/177411_2.png) [@trunghai](https://forum.uipath.com/u/trunghai)\
**Post date:** [30.Март.2020 06:02:40 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/14 "2020-03-30T06:02:40Z")

</div>

Thanks you but i want to do as below :

I want to add VBA code into this activity and declare arguments.

 ![Capture](https://global.discourse-cdn.com/uipath/original/3X/e/2/e2ecb3487baebc063b2a5ae7f6ba37d2ffbc041c.jpeg)

---

<div class="post-metadata">

**Author:** ![Cristian\_Bardas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/cristian_bardas/32/60932_2.png) [@Cristian\_Bardas](https://forum.uipath.com/u/Cristian_Bardas)\
**Post date:** [30.Март.2020 06:05:05 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/15 "2020-03-30T06:05:05Z")

</div>

Invoke Code uses [vb.net](http://vb.net), while Excel needs VBA code, that’s also the reason they are separated activities in UIPath.

![image](https://global.discourse-cdn.com/uipath/original/3X/5/a/5a1cd46bf733085a7ebd53ebe5237c677e5ac2ee.png)

 ![image](https://global.discourse-cdn.com/uipath/original/3X/0/4/049b50eb22ecf4c0f9801eab2ddb6e15b60b7f91.png)

---

<div class="post-metadata">

**Author:** ![trunghai](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/trunghai/32/177411_2.png) [@trunghai](https://forum.uipath.com/u/trunghai)\
**Post date:** [30.Март.2020 06:07:24 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/16 "2020-03-30T06:07:24Z")

</div>

Understood 🙂

Thanks you very much bro!

---

<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:** [02.Апрель.2020 06:08:36 UTC](https://forum.uipath.com/t/declaration-in-invoke-code/206379/18 "2020-04-02T06:08:36Z")

</div>

Закрыл(а) тему 02.Апрель.2020 06:08:36 UTC

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