Declaration in Invoke Code

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

1 Like

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

Thanks
@trunghai

3 Likes

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

4 Likes

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.

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


Then inside the code use CellRange as,
For Each Cell In Sheet6.Range(CellRange).

3 Likes

Hi Bro @Manish540

I have create argument as your guide.

But it has something wrong.

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

1 Like

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

2 Likes

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”

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 (8.0 KB)

Here you go, it should be what you need.

ExcelVBA.zip (24.4 KB)

1 Like

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.

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

1 Like

Thanks you but i want to do as below :

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

Invoke Code uses vb.net, while Excel needs VBA code, that’s also the reason they are separated activities in UIPath.

image

2 Likes

Understood :slight_smile:

Thanks you very much bro!

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