在BluePrism中工作时,运行Excel宏打开另一个工作簿时出现问题。
我有一个宏启用excel工作簿Sub
中的\\myCompany\myFolder\myMasterbook.xlsm
打开另一个工作簿
Public Sub OpenMyFile(Optional book2open As String = "")
Dim openedBook As Workbook
Debug.Print "About to open", book2open
Set openedBook = Application.Workbooks.Open(book2open)
If openedBook Is Nothing Then
Debug.Print "Could not open it"
Else
Debug.Print "I found", openedBook.Worksheets(1).Cells(1, 1).Value
' Actually, I do a lot more with that workbook, of course
openedBook.Close
End If
End Sub
当,在立即窗口(用qazxsw poi打开)中,我进入
Ctrl-G
我看到工作簿打开和关闭,并在立即窗口中获得响应
call OpenMyFile ("\\myCompany\myFolder\myWorkbook.xlsx")
在机器人自动化过程(RPA)中,使用BluePrism,我需要打开包含此VBA About to open \\myCompany\myFolder\myWorkbook.xlsx
I found Cell A1 content
的工作簿并运行它。在Immidiate窗口,我现在得到了
Sub
我尝试了两件事来解决它
如果我在VBA中定义我的About to open \\myCompany\myFolder\myWorkbook.xlsx
Could not open it
Sub
并用Public Sub OpenMyFile(Optional book2open As String = "\\myCompany\myFolder\myWorkbook.xlsx")
调用它,但这并不能解决我的问题,因为我需要将OpenMyFile
传递给VBA。
如果我在VBA中将book2open
定义为Sub
,我会收到此错误:`内部:无法执行代码阶段,因为代码阶段引发的异常:无法运行宏
'OpenMyFile(“C:\ Users \ P01549 \ Documents \ TestHorsten.xlsx”, - 1)'。宏可能在此工作簿中不可用,或者可能禁用所有宏
Public Sub OpenMyFile(book2open As String')
对象使用互操作dot.net代码的一部分可以在BluePrisms Object Studio中找到。我运行此对象的以下“操作”
MS Excel VBO - Extended
Dim excel as Object = CreateObject("Excel.Application")
' Create a GUID with which we can kill the instance later
' if we have to play hardball to get rid of it.
excel.Caption = System.Guid.NewGuid().ToString().ToUpper()
handle = GetHandle(excel)
同
Dim wb as Object = GetInstance(handle).Workbooks.Open(filename)
name = wb.Name
wb.Activate()
:Create Instance返回的句柄handle
:filename
\\myCompany\myFolder\myMasterbook.xlsm
同
GetInstance(Handle).Run(Macro_Name)
:Create Instance返回的句柄handle
:Macro_Name
有没有人有解释或工作的声音?
通常情况下,Application.Run将函数的参数作为单独的参数:
此参数不适用于Application.Run:OpenMyFile("\\myCompany\myFolder\myWorkbook.xlsx")
您可以尝试修改VBO以使用带参数的run参数:编写另一个名为“Run Macro With Parameter”的代码阶段(或者您想要调用的任何代码)
OpenMyFile("\\myCompany\myFolder\myWorkbook.xlsx")
其中Macro_Name是“OpenMyFile”,param1是“\\ myCompany \ myFolder \ myWorkbook.xlsx”