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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
hi!
try this one!
ActiveCell.FormulaR1C1 = "=[phonesasdf.xls]Sheet2!R1C1"
 

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
hi!
when the workbook is close use this one.

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

onlyadrafter

Well-known Member
Joined
Aug 19, 2003
Messages
5,703
Platform
  1. Windows
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.
 

Carly

Active Member
Joined
Aug 21, 2002
Messages
370
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
 

Watch MrExcel Video

Forum statistics

Threads
1,130,118
Messages
5,640,216
Members
417,131
Latest member
Seanr19871

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
Top