如何在VBA中将对象返回到UiPath?

问题描述 投票:0回答:2

我正在尝试从函数 Find123 返回一个对象。我已从子过程 Retrieve123 中调用它。

当我完成时,它说函数未定义,并突出显示 CObj 方法。

你能告诉我一种将整数或字符串转换为对象并在VBA中返回它的方法吗?

Sub Retrieve123()
    Call Find123()
End Sub

Function Find123()As Object
    Dim val As String
    val="100"
    Dim obj As Object
    Set obj=CObj(val)
    Set Find123 = obj
End Function

这就是我收到错误消息的方式

当我将字符串值分配给函数时,它会给出这种类型不匹配错误。

我需要将字符串转换为对象,因为在 UiPath 中我们只能返回对象类型,因为调用 VBA 活动的输出是对象类型。

excel vba uipath
2个回答
0
投票

您不必将任何内容转换为对象,但 UiPath 将

Invoke VBA
活动的返回值视为对象(因为它不知道返回的是什么)。您可以安全地从函数返回原始类型 - 在您的情况下为
integer
- 将其存储在 UiPath 中的对象类型变量中,然后再次将其转换为整数。

这是一个一般示例。请注意,

result
object
类型,而
i
integer
。在
Assign
活动中,
i
被转换为
integer

VB.NET 等效项:

i = CType(result, Integer)


0
投票

我用它来处理错误

子ttt() Dim x 作为整数

On Error GoTo abc
x = "ss" ' This line will raise an error

For x = 1 To 10
    Cells(x, 1).Value = 100
Next x

Exit Sub ' Go to Done if no error

完成: 退出子程序 ABC: '将 errMsg 调暗为字符串 errMsg = Err.Number & " " & Err.Source & " " & Err.Description

' Print the error message to the Immediate Window
Debug.Print errMsg

' Return the error description back to UiPath
ll = errMsg
Exit Sub

结束子

但是由于输出返回空值,如何将错误值检索到 uipath?

© www.soinside.com 2019 - 2024. All rights reserved.