RPA-UIPath-006 VBA&SAP
RPA-UIPath-VBA Marco
UIPath可以使用Excel application Scope+Execute Macro兩個(gè)Activity來運(yùn)行EXCEL宏文件的Marco代碼

Execute Macro中填寫要執(zhí)行的Marco名稱
這里UIPath執(zhí)行的操作相當(dāng)于打開宏文件執(zhí)行Marco
或使用Excel application Scope+Invoke VBA兩個(gè)Activity來運(yùn)行EXCEL的宏代碼

Invoke VBA中填寫要執(zhí)行Marco的txt文件路徑和Marco名稱
這里UIPath執(zhí)行的操作相當(dāng)于打開Excel文件,將txt宏代碼加載到Excel中并運(yùn)行Marco
另外還可以在VBA Marco與UIPath傳入傳出變量
在Execute Macro和Invoke VBA的屬性中設(shè)置
InputParameters,像{TemplatePath,CustomerList}
OutputValue,像RunMarcoResult

VBA代碼格式如下
Function Make_Statement(TemplatePath, CustomerList As String) As String
'
'
'
Make_Statement = "OK"
'
'
'
End Function
RPA-UIPath-SAP
通過EXCEL的Marco來控制SAP進(jìn)行一系列SAP操作是使用UIPath-VBA Marco來解決SAP相關(guān)RPA的優(yōu)質(zhì)解決方案。
SAP本身就有錄制和運(yùn)行功能
需將SAP做如下圖設(shè)置CustomizeLocalLayout---Options---Scripting---UserSetting勾選如下

在CustomizeLocalLayout---Script Recording and Playback啟動(dòng)Record and Playback


點(diǎn)擊Record開始錄制SAP操作
停止后錄制的代碼在Save To的路徑下
將錄制的代碼以txt的格式打開,即得到剛剛在SAP的操作代碼
將錄制的SAP的操作代碼以VBS的默認(rèn)打開方式打開,在Start Process Activity中啟動(dòng),可執(zhí)行一些不含變量或參數(shù)的SAP固定操作

整理修改得到SAP的操作代碼,得到樣式如下的宏代碼
需將下面的紅字代碼替換為綠字代碼方可在EXCEL的Macro中使用
原因:紅字代碼為直接操作SAP代碼,需加工為綠字代碼才可以在EXCEL的Macro中在執(zhí)行操作SAP
Sub Test
'
'
'
If Not IsObject(applicationSAP) Then
? ? Set SapGuiAuto = GetObject("SAPGUI")
? ? Set applicationSAP = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(ConnectionSAP) Then
? ? Set ConnectionSAP = applicationSAP.Children(0)
End If
If Not IsObject(session) Then
? ? Set session = ConnectionSAP.Children(0)
End If
If IsObject(WScript) Then
? ? WScript.ConnectObject session, "on"
? ? WScript.ConnectObject applicationSAP, "on"
End If
'
'
'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
'
'
'
End Sub