Refering to a Closed Workbook

Carly

Active Member
Joined
Aug 21, 2002
Messages
370
I have used the following if statement in VBA

If Range("B2") = "Nov" Then _
MsgBox "Nov", vbInformation Else _
MsgBox "Error", vbInformation

This works fine but only if I open the workbook that I am referring to. Is it possible to work this statement without opening. I tried:

If Workbooks("\\sysdevweb\bw\PricingMethods\Data\Dates.xls").Sheets("Dates").Range("B2") = "Nov" Then _
MsgBox "Nov", vbInformation Else _
MsgBox "Error", vbInformation

but this brings back error - 'Subscript out of range'

Any help appreciated!

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
hi!
when the workbook is close use this one.

ActiveCell.FormulaR1C1 = "='C:\test\[phonesasdf.xls]Sheet2'!r1c1"
 
Upvote 0
Hello,

Can you not have a cell in your open spreadsheet with = (and select the cell from the other sheet (e.g. =[clock.xls]Sheet2!$B$2).

You can then refer to this cell in you VB Code.
 
Upvote 0
I don't want to create a reference within my open workbook to the closed workbook I just want to refer to the contents of the cell in the closed workbook.

i.e. IF (contents of cell in closed workbook) = "NOV" then MsgBox("ok")
else MsgBox("Not OK")

If I used ActiveCell.FormulaR1C1 = "=[phonesasdf.xls]Sheet2!R1C1", I would then have to refer to the activecell in the IF statement and then clear out the contents the remove the reference
 
Upvote 0

Forum statistics

Threads
1,214,625
Messages
6,120,598
Members
448,973
Latest member
ksonnia

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