0

问题:我需要在已关闭的工作簿中搜索特定值,然后返回匹配字符串的行号,或者更优选地返回具有匹配字符串行号的值。

我试图让它与该ExecuteExcel4Macro功能一起使用,我的代码可以在下面找到。

Private Function GetInfoFromClosedFile2(ByVal wbPath As String, ByVal wbName As String, ByVal wsName As String, ByVal colNum As Integer, ByVal searchString As String) As Variant
Dim arg As String
    GetInfoFromClosedFile2 = vbNullString
    If Right(wbPath, 1) <> "\" Then wbPath = wbPath & "\"
    If Dir(wbPath & wbName) = vbNullString Then Exit Function
    arg = "'" & wbPath & "[" & wbName & "]" & wsName & "'!" & Worksheets(wsName).Columns(colNum).Find(What:=searchString).Address(True, True, xlR1C1)
    'On Error Resume Next
    GetInfoFromClosedFile2 = ExecuteExcel4Macro(arg)
End Function

arg =我在线上收到运行时错误“9”

4

1 回答 1

0

我相信你所要求的实际上可以在没有 VBA 的情况下完成。只要正确引用了工作簿,您就可以在编辑栏中编写一个 Index(Match) 函数来搜索已关闭的工作簿。

您可以通过在编写公式时同时打开两个工作簿,然后关闭您引用的工作簿来实现此目的。Excel 应在公式中保留文件位置,此时它成为数据连接。

于 2017-08-08T15:02:34.593 回答