Sub MakeFormulas()
Set sh = ThisWorkbook.Sheets(1)
wbname = ThisWorkbook.Name
With Application.FileDialog(msoFileDialogOpen)
.InitialFileName = ThisWorkbook.Path & "\*.xls*"
.Title = "Please Select a File"
.AllowMultiSelect = False
.Show
If .SelectedItems.Count = 0 Then Exit Sub ' User clicked cancel: Exit
strfile = .SelectedItems(1)
End With
Set mybook = Workbooks.Open(strfile)
SelFile = Right(strfile, Len(strfile) - InStrRev(strfile, "\"))
Windows(wbname).Activate
Range("D1:D6").Formula = _
"=VLOOKUP($A1,'[" & SelFile & "]Sheet1'!$A$2:$F$13,6,)"
Range("E1:E6").Formula = _
"=VLOOKUP($A1,'[" & SelFile & "]Sheet1'!$A$2:$H$13,8,)"
End Sub
Bookmarks