Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Getting value from closed workbook

I have found the following function :

Private Function GetValue(path, file, sheet, ref)
' Retrieves a value from a closed workbook
Dim arg As String

' Make sure the file exists
If Right(path, 1) < "\" Then path = path & "\"

If Dir(path & file) = "" Then
GetValue = 0
Exit Function
End If

' Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address()


' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function


in my cell I have a formula that calls a function call Calc_Calls

Function calc_calls(fn)
file = fn & ".xls"
path = "\\sth-data\Ops Data\CSATS"
calc_calls = GetValue(path, file, "Report", "C7")
End Function


the value in fn is 07042004

The result of the arg value (from GETVALUE function) is '\\sth-data\Ops
Data\CSATS\[07042004.xls]Report'!$c$7 the function returns 0 if the file
does not exist which is correct - but #Value error when a file exists. I
have pasted the result of ARG directly in to a cell (preceeding with =") and
it works fine.

Any ideas ?

Many thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default Getting value from closed workbook

This looks suspiciously like the code on John Walkenbach's site:
http://j-walk.com/ss/excel/eee/eee009.txt

And it can't be used in a cell on a worksheet--even if you try to bury it in
other functions (xl is too smart).

But Harlan Grove posted a function that opens another instance of excel and then
retrieves the value from that closed workbook.

http://google.com/groups?threadm=oZx...wsra nger.com

Dyawlak wrote:

I have found the following function :

Private Function GetValue(path, file, sheet, ref)
' Retrieves a value from a closed workbook
Dim arg As String

' Make sure the file exists
If Right(path, 1) < "\" Then path = path & "\"

If Dir(path & file) = "" Then
GetValue = 0
Exit Function
End If

' Create the argument
arg = "'" & path & "[" & file & "]" & sheet & "'!" & _
Range(ref).Range("A1").Address()

' Execute an XLM macro
GetValue = ExecuteExcel4Macro(arg)
End Function

in my cell I have a formula that calls a function call Calc_Calls

Function calc_calls(fn)
file = fn & ".xls"
path = "\\sth-data\Ops Data\CSATS"
calc_calls = GetValue(path, file, "Report", "C7")
End Function

the value in fn is 07042004

The result of the arg value (from GETVALUE function) is '\\sth-data\Ops
Data\CSATS\[07042004.xls]Report'!$c$7 the function returns 0 if the file
does not exist which is correct - but #Value error when a file exists. I
have pasted the result of ARG directly in to a cell (preceeding with =") and
it works fine.

Any ideas ?

Many thanks


--

Dave Peterson

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
Reference to closed workbook Francis Brown Excel Discussion (Misc queries) 2 December 1st 08 10:13 PM
Value from a closed workbook Anthony Slater Excel Discussion (Misc queries) 5 May 17th 05 09:49 AM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM
Run a Macro over a Closed Workbook?? John[_78_] Excel Programming 8 February 25th 04 02:28 PM
Update Closed Workbook w/ ADO AL Excel Programming 4 February 11th 04 01:59 AM


All times are GMT +1. The time now is 12:03 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"