Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
todays's function, if I open file date changes MaT Excel Discussion (Misc queries) 1 November 22nd 07 07:45 PM
workbooks.open function fails to open an existing excel file when used in ASP, but works in VB. san Excel Programming 1 January 3rd 06 03:22 AM
File Browse Function (Open dialog box for choosing file) b-123 Excel Programming 1 August 25th 05 10:06 PM
How to insert Open File action in the IF Function? Majesty Excel Discussion (Misc queries) 1 August 23rd 05 03:43 PM
Which function to use to open an .asc file? Real Name Excel Programming 1 July 31st 04 05:54 AM


All times are GMT +1. The time now is 02:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"