Hey I have got the code below. I wanna be able to open mutiple workbooks through application.getopenfilename and then extract the respective book names to compare them to a list.
I don't why but whenever I try to extract the workbook name the " Object required" error pop's up. In this exactract I used dir, but if I use name or path the result is the name, same error pop's up if I try to use Filenales (i) instead of active workbook. Could someone help me or explain me what actually happens? Thank you in advance,
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