![]() |
Function to open file
In Excel2000, I have the following function:
Function WC_Name(ByVal WC) WC_Name = Application.WorksheetFunction.VLookup(WC, Workbooks("master.xls").Worksheets("fall06").Range ("b4:n500"), 13, False) End Function The problem is that it does not work if the "master" file is not open. How can I have the function open the file if it isn't already? Thanks |
Function to open file
Try this...
Function WC_Name(ByVal WC) dim wbk as workbook on error resume next set wbk = Workbooks("master.xls") on error goto 0 if wbk is nothing then set wbk = Workbooks.Open("C:\master.xls") end if WC_Name = Application.WorksheetFunction.VLookup(WC, _ wbk .Worksheets("fall06").Range("b4:n500"), 13, False) End Function -- HTH... Jim Thomlinson "snax500" wrote: In Excel2000, I have the following function: Function WC_Name(ByVal WC) WC_Name = Application.WorksheetFunction.VLookup(WC, Workbooks("master.xls").Worksheets("fall06").Range ("b4:n500"), 13, False) End Function The problem is that it does not work if the "master" file is not open. How can I have the function open the file if it isn't already? Thanks |
Function to open file
Are you sure this works with a function. It still only wotrks with the
file open. Thanks anyway. Jim Thomlinson wrote: Try this... Function WC_Name(ByVal WC) dim wbk as workbook on error resume next set wbk = Workbooks("master.xls") on error goto 0 if wbk is nothing then set wbk = Workbooks.Open("C:\master.xls") end if WC_Name = Application.WorksheetFunction.VLookup(WC, _ wbk .Worksheets("fall06").Range("b4:n500"), 13, False) End Function -- HTH... Jim Thomlinson "snax500" wrote: In Excel2000, I have the following function: Function WC_Name(ByVal WC) WC_Name = Application.WorksheetFunction.VLookup(WC, Workbooks("master.xls").Worksheets("fall06").Range ("b4:n500"), 13, False) End Function The problem is that it does not work if the "master" file is not open. How can I have the function open the file if it isn't already? Thanks |
All times are GMT +1. The time now is 01:37 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com