RPA BluePrism Excel VBO扩展

时间:2019-01-30 23:53:21

标签: excel blueprism rpa

我正在尝试在BluePrism中创建一个excel VBO操作,该操作可以在excel中查找文本并返回单元格值

Dim excel as Object = GetInstance(handle)
Dim strText as String = Text
Dim ws as Object
ws = GetWorksheet( _
     handle, workbook_name, worksheet_name, False)
Dim r as Object
r = ws.Range("1:1")
r.Activate()
Dim cell as Object = excel.ActiveCell
Dim s as Object
s = ws.Cells.Find(What:=[Text], After:=cell, _
Lookin:="xlWhole", SearchOrder:="xlByColumns", SearchDirection:="xlNext", _
MatchCase:=False, SearchFormat:=False)
s.Activate()
cellref = ws.ActiveCell.Address(False,False)

这在具有错误索引不匹配的查找功能时失败。我不确定这里出了什么问题

基本上我正在执行此操作,因为我有大量文件,其中必须搜索特定值并在找到的值的上方和下方提取几行。当我尝试将工作表作为集合时,它以“内存不足”异常失败。

有没有办法使用现有的VBO来做到这一点?如果不能,谁能帮助我编写VBO在excel中查找文本?

2 个答案:

答案 0 :(得分:1)

如果GetHandle()失败,则意味着您传递的handle值所描述的Excel实例不存在。

使用Excel VBO的相同实例启动MS Excel实例,或附加到现有实例并为新VBO获得单独的handle值。 handle不能在VBO的实例/副本之间转移。

答案 1 :(得分:0)

我在我的环境中实现了很好而整洁的excel方法Find()。我希望这足以使您前进。

dim nLookin as long
if LookIn = "xlFormulas" then
    nLookIn = -4123
elseif LookIn = "xlValues" then
    nLookIn = -4163
elseif LookIn = "xlComments" then
    nLookIn = -4144 
else
    Throw New System.Exception("Incorrect parameter passed for LookIn")
end if

dim nLookAt as long
if LookAt = "xlPart" then
    nLookAt = 2
elseif LookAt = "xlWhole" then
    nLookAt = 1
else
    Throw New System.Exception("Incorrect parameter passed for LookAt")
end if

dim nSearchDirection as long
if SearchDirection = "xlNext" then
    nSearchDirection = 1
elseif SearchDirection = "xlPrevious" then
    nSearchDirection = 2
else
    Throw New System.Exception("Incorrect parameter passed for SearchDirection")
end if

dim oWS as object
dim oResult as object
oWS = GetWorksheet(Handle,nWB,nWS, False)


oResult = oWS.Range(nR).Find(what:=Value, LookIn:=nLookin, MatchCase:=MatchCase, LookAt:=nLookAt, SearchDirection:=nSearchDirection)


if oResult is nothing then
    Address = "Not found"
    Column = "A"
    Row = 1
else
    Address = oResult.address
    'Convert_to_Letter(oResult.Column, Column)
    Row = oResult.Row
End If

oWS = nothing
oResult = nothing

Parameters used