VBA: "Evaluate" does not work with closed workbooks, but the same function does on sheet

kocas

New Member
Joined
Jun 19, 2007
Messages
6
here is a sample code:

Code:
Public Function getest(esttype, yr)
Dim strf As String

strf = "=counta('m:\folder\mds\[rating index.xls]" & esttype & Right(yr, 2) & "'!$1:$1)"

MsgBox Evaluate(strf)



End Function

for "sales" and 2009, what strf reads is:

Code:
=counta('m:\folder\mds\[rating index.xls]sales09'!$1:$1)

when i evaluate this string, i get "1" in the msgbox.

the exat same string returns 80 when i put it in a cell.

if i use Vlookup in a similar way, evaluate gives type mismatch error.

Any ideas ?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
well, i was in denial : )

the thing is, i can get around this when i am working in subs. I use a temporary named cell say temp, and i go

Code:
[temp].formula = strf

whateverineed = [temp].value

[temp].clearcontents


but as you may know, i cannot use this with udfs, as they dont edit any cell other than they are housed by. Just wondering whether anyone gave this a thought.

Making this work would make life very easy. Closed-workbook data pulling would work like a champ. Well, it kind of already is, if i use subs.

p.s. calling a sub from a func does not work either.


thanks for the reply Andrew.
 
Upvote 0
The fact that you are using a variable named fpath indicates that the workbook isn't open.

I don't see it that way. You can put in the fully qualified workbook path using that structure the OP used, and Excel will remove the path if the workbook is opened. It is a little unnerving.

Say Andrew, I don't know much about Excel4Macros but... could you possibly get any of those to give information about a closed workbook?
 
Upvote 0

Forum statistics

Threads
1,214,628
Messages
6,120,618
Members
448,973
Latest member
ChristineC

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