Uipath调用Macro(invoke VBA/Execute Macro/invoke VBScript)

The RPA project will run certain processes semi-automatically or fully automatically according to the actual situation, sometimes it can be completed in a few minutes, sometimes it takes a whole day to run.

As developers, users, operation and maintenance personnel, it is impossible to stare at the RPA running or watch the activity log every time (assuming everyone is lazy, in fact, the actual situation is lazier than assumed), RPA needs to generate a report after running the current process ( Or kibana). The complex will record which documents are processed and the success rate. A simple report or even an email tells the user that I have finished running and went to rest.

The current project encounters users who need to see the current running status table exported from the database, the table is like this

id id2 status
100 1000 done
100 1001 error
100 1002 done
101 1003 done
102 1004 done
102 1005 done

What users want to see is this

id id2 status
100 1000 done
1001 error
1002 done
101 1003 done
102 1004 done
1005 done

Uipath cannot directly operate the Excel interface. Is there any way?

Can use other languages, macro, powershell...

Here we have selected macro, how does uipath call macro? invoke code! But the invoke code cannot omit the statement defining various variables like in the alt+f11 window. So the invoke code is passed.

Fortunately, there are other things, we found invoke VBA, write the macro in bas or txt (bas is more recommended). Excel application scope indicates the operation Excel, and invoke VBA is added to it, and the path and method name are filled in the properties, done!

Sub Macro1()
'
' Macro1 Macro
'

'
On Error Resume Next
Application.DisplayAlerts = False

For i = 2 To Range("A65535").End(xlUp).Row //只看A列
If Range("A" & i) <> Range("A" & (i - 1)) Then
     
     
     If i <> 2 Then
            Range("A" & rangeIndex & ":A" & (i - 1)).Select
            With Selection
                .HorizontalAlignment = xlCenter
                .VerticalAlignment = xlBottom
                .WrapText = False
                .Orientation = 0
                .AddIndent = False
                .IndentLevel = 0
                .ShrinkToFit = False
                .ReadingOrder = xlContext
                .MergeCells = False
            End With
            Selection.Merge
     End If
     rangeIndex = i
End If

Next

    Range("A" & rangeIndex & ":A" & Range("A65535").End(xlUp).Row).Select
    With Selection
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Merge
    Application.DisplayAlerts = True
ActiveWorkbook.RemovePersonalInformation = False //关闭Excel自动提示内容还是格式有变的弹框
End Sub

--------------------

Execute Macro

It needs to be placed in the Excel Application Scope, and the Macro code is written in Visual Basic for Application.

------------------------------

invoke VBScript

 

Guess you like

Origin blog.csdn.net/weixin_31808811/article/details/105404187