How do I use this VBA in uipath


I want to use this VBA in may workflow. but i do not know hot to use invoke code or invoke vba
please help me (i want sample)


Option Explicit

Sub split_As_per_Rows()

Dim rngAll As Range                           
Dim SplitLine As Integer                     
Dim rowsCount As Long, colsCount As Integer   
Dim strPath As String                         
Dim i As Long                                
Dim rowsNo As Long                           
Dim rngSplit As Range                        
Dim strName As String

Application.ScreenUpdating = False      
Set rngAll = ActiveSheet.UsedRange      
SplitLine = 50                       
rowsCount = rngAll.Rows.Count          
colsCount = rngAll.Columns.Count        
strPath = ThisWorkbook.Path & Application.PathSeparator   

With ThisWorkbook
  strName = Left(.Name, Len(.Name) - 5) 
End With

For i = 2 To rowsCount Step SplitLine                                    
    rowsNo = i + SplitLine                                              
    Set rngSplit = Range(Cells(i, 1), Cells(rowsNo + 1, colsCount))      
    rngAll.Rows(1).SpecialCells(2).Copy Cells(1, 1)                     
    Range(Cells(2, 1), Cells(SplitLine + 1, colsCount)) = rngSplit.Value

    ActiveWorkbook.SaveAs strPath & strName & "(" & ((i - 1) \ SplitLine) + 1 & ").csv", FileFormat:=xlOpenXMLWorkbook
Next i

Set rngAll = Nothing   
Set rngSplit = Nothing

End Sub

1 Like

Please find the attached file for the sample workflow how to trigger the VBA code from UIPath.

Invoke (15.7 KB)



Thank you .

I can’t open your sample.
and I don’t know how do I set argument in my workflow…

That sample is from UIPath docs.

Follow these steps:

Save the Macro in a text file with a .txt extension.

Use Invoke VBA activity and pass the below inputs -

If any arguments need to pass to the method, pass in the “Entry Method Parameters

Karthik Byggari

Thank you

I solved!!!

1 Like
    • Save the Vb code in a simple text file.
    • call the text file in invoke VBA code Activity.
    • place the invoke vba code activity in a Excel Application Scope Activity.
    • Invoke VBA code Activity works only inside Excel App Scope.


Try to rename the .txt file into .bas (basic) and call it through invoke VBA.
Good luck!

I have similar issue. When I try to use Invoke VBA , it does’t work . But the same works using Execute Macro.
Below is the error which I get using Invoke VBA:

Sample Workflow:

Below is Macro or VB script:
Sub EditWorkbook()
** ActiveWorkbook.LockServerFile**
End Sub

execute macro is working because it is inside the excel application scope already. its like we are executing a macro developed inside excel in developer tab.

Invoke VBA refers to a separate file. That’s why we need to include it in a txt file.