首页 > 解决方案 > Uipath 错误:“此工作簿中可能没有宏”?

问题描述

我正在尝试使用 UIPath 调用 VBA 活动从 Excel 工作表中检索单元格地址。

我是 VBA 编码的新手。我编写了一个函数来检索单元格地址数组,并且编写了一个子过程来调用该函数。

我正在调用 UIPath 活动中名为“调用 VBA”的子程序。当我运行它时,它说

调用 VBA:无法运行宏“Main”。该工作簿中的宏可能不可
用,或者所有宏都可能被禁用。

这是我在 Excel 中启用宏的屏幕截图: 截屏

Sub Main(Amount As Integer)
    Call findcellFunction(Amount)
End Sub

Function findcellFunction(Amount As Integer)As Collection
    On Error Resume Next
    Dim rngX As Range           
    Dim WS As Worksheet
    Dim datax As Range
    Dim cellAddress As Variant
    Dim index As Integer
    Dim iTotal As Integer
    Dim CellArray 
    iTotal = 0
    Set CellArray = New Collection
    'Iterate until all cell values are found
    For index=1 To Amount
        Set rngX = Worksheets("rptBOMColorPrint").Range("A1:EZ50").Find("Colour Name", lookat:=xlPart)
        If Not rngX Is Nothing Then
            MsgBox "Found at " & rngX.Address
            CellArray.Add rngX.Address
        End If
        Cells(rngX.Row,rngX.Column).Delete
        iTotel =iTotal + index
    Next index
    'shows list that has been populated with cell addresses
    For Each cellAddress In CellArray
        MsgBox "list populated " & cellAddress
        Range(cellAddress).Value = "Colour Name"
    Next
    CellArray = findcellFunction(Amount)
End Function

这就是我从 UIPath 活动中调用 VBA 的方式。 我如何从 UIPath 调用 VBA 宏

标签: excelvbarpauipath

解决方案


当您包含 .xlsx excel 文件而不是 .xls 文件时,它可以工作。这是因为 Uipath 调用 VBA 活动不支持 .xls 文件,因为它是旧版本。


推荐阅读