simonphillips
New Member
- Joined
- Mar 25, 2008
- Messages
- 32
- Office Version
- 365
- Platform
- Windows
Hi Everyone,
Thanks in advance for any assistance you can provide !
I am attempting to complete a series of "vlookup" function calls across ~150 files from a single workbook WITHOUT having to open each file.
I have attempted to write a function (inserted below) that returns the value of the lookup to a cell and as inputs it has the filename and lookup params
But I suspect that the file needs to be open for this function call to work ?
Any assistance would be appreciated
Thanks in advance for any assistance you can provide !
I am attempting to complete a series of "vlookup" function calls across ~150 files from a single workbook WITHOUT having to open each file.
I have attempted to write a function (inserted below) that returns the value of the lookup to a cell and as inputs it has the filename and lookup params
But I suspect that the file needs to be open for this function call to work ?
Any assistance would be appreciated
VBA Code:
Function getexternaldata(Filename As String, Filenamerange As Variant, ProjectID As Variant, Year As String, Column As Variant) As Variant
On Error GoTo ErrHandler
Application.ScreenUpdating = False
Dim src As Workbook
' OPEN THE SOURCE EXCEL WORKBOOK IN "READ ONLY MODE".
Set src = Workbooks.Open(Filename, True, True)
' Vlookup the value from the SOURCE WORKBOOK.
getexternaldata = Application.VLookup(ProjectID, Filenamerange, Column, 0)
' CLOSE THE SOURCE FILE.
src.Close False ' FALSE - DON'T SAVE THE SOURCE FILE.
Set src = Nothing
ErrHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Function