嘿,我有下面的代码。我希望能够通过 application.getopenfilename 打开多个工作簿,然后提取相应的书名以将它们与列表进行比较。
我不知道为什么,但每当我尝试提取工作簿名称时,都会弹出“需要对象”错误。在这个精确文件中,我使用了 dir,但如果我使用名称或路径,结果就是名称,如果我尝试使用 Filenales (i) 而不是活动工作簿,则会弹出相同的错误。有人可以帮助我或向我解释实际发生的情况吗?先感谢您,
Sub importDealflow()
Dim twb As Workbook, aWB As Workbook
Dim Userrange As Range, cell As Range
Dim Defaultrange As Range
Dim x As Long, Ent As Variant
Dim FileNames() As Variant, nw As Integer
Dim i As Integer
Dim FN As String, pth() As Variant
Dim Getbook As String
Set twb = ThisWorkbook
Set Userrange = twb.Sheets("Deal Workflow").Range("G5:G28")
FileNames = Application.GetOpenFilename(FileFilter:="Excel Filter(*.xlsx),*xlsx", Title:="Open File(s)", MultiSelect:=True)
nw = UBound(FileNames)
For Each cell In Userrange
If cell.Value <> "" Then
Ent = Mid(cell, InStr(cell, "(") + 1, InStr(cell, ")") - InStr(cell, "(") - 1)
End If
For i = 1 To nw
Workbooks.Open FileNames(i)
Set aWB = ActiveWorkbook
Set Getbook = Dir(ActiveWorkbook)
If Left(pth, InStr(pth(i), "-" - 1)) = Ent Then
MsgBox Ent
End If
Next i
Next
End Sub