Achieve same thing as Indirect Function, with closed files

danrofohio

New Member
Joined
Mar 14, 2012
Messages
4
I have a situation where I want to refer to cells in many different workbooks. The Indirect function will work if I have all of the external workbooks open, but I have far too many to open at the same time. Is there some way accomplish the same thing without manually entering all of the external reference formulas? In other words, I want to use a formula that gets the file name from another cell.

Thanks,
Dan R.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
not sure if this is what you are looking for, but something like this might work.

cant find where i originally found the "getValue" function...somewhere on Chip Pearson's site (is modified a tad).

Code:
Function pathEx(path As String) As Boolean

On Error Resume Next
pathEx = dir(path, vbDirectory) <> vbNullString
End Function

Function getFile(path As String, Optional tst As Boolean) As String

On Error GoTo exitFunc
tst = False
If Right$(path, 1) = "\" Then GoTo exitFunc
getFile = Right$(path, Len(path) - InStrRev(path, "\"))
tst = True
exitFunc:
End Function

Function getFold(path As String, Optional tst As Boolean) As String

tst = False
On Error GoTo exitFunc
getFold = Left$(path, InStrRev(path, "\") - 1)
tst = True
exitFunc:
End Function

'got this from cPearson
Function getValue(fullPath As String, wsName As String, _
                            rngAd As String, _
                            Optional tst As Boolean) As Variant
'   Retrieves a value from a closed workbook
    tst = False
    On Error GoTo exitFunc
'   Make sure the file exists
    If Not pathEx(fullPath) Then getValue = "": Exit Function
'   Make sure is an excel document
    If Not fullPath Like "*.xl*" Then Exit Function
'   Execute an XLM macro
    getValue = ExecuteExcel4Macro("'" & getFold(fullPath) & "\[" & getFile(fullPath) & "]" & wsName & "'!" & _
    Range(rngAd).Cells(1).Address(, , xlR1C1))
'   No error so tst=true:
    tst = True
exitFunc:
End Function


paste that into a standard code module
if you supply that with the full workbook name, the sheet name, and the address of the cell you want it should work.
 
Upvote 0
Hello to the Forum,

there are a number of ways to do this,
Install the MOREFUNC addin (google for Indirect.Ext) this works on closed workbooks or you could use sumproduct formula instead
 
Upvote 0
@kevin,

I read some articles on the web about the morefunc addin that said they won't work with Office 2010. What is your experience with that?


Dan
 
Upvote 0
Hi Dan,

sorry not used it on 2010, so you can either use sumproduct or the VBA code that chirp provided
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,085
Members
449,206
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top