Check if multiple workbooks are open

Ignition1

New Member
Joined
Feb 22, 2011
Messages
49
I have a spreadsheet with a block of VBA code which updates the data by pulling information for other workbooks.

At first I used to make the code open the workbooks (using the file locations - C:\Windows etc etc) - but then I realised the file location won't be the same for everyone who uses this. The only alternative I could think of is if they have the workbooks all open before they run the updating macro.

So to check if the workbooks are all open I tried this -

Code:
Dim Prospectswb, Workloadwb, TGCwb As Workbook
On Error Resume Next

Set Prospectswb = Workbooks("Prospects.xls")
Set Workloadwb = Workbooks("Workload.xls")
Set TGCwb = Workbooks("TGC.xls")

If Prospectswb Or Workloadwb Or TGCwb Is Nothing Then

MsgBox ("Please make sure all workbooks are open and that they are named 'Prospects', 'Workload' and 'TGC' only")

Else: Call UPDATE

End Sub

UPDATE is a sub-procedure which I'd like it to run If all the workbooks above are open. If they are not open then I'd like the message box above to appear.

Any help would be much appreciated!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Perhaps

Code:
If Prospectswb Is Nothing Or Workloadwb Is Nothing Or TGCwb Is Nothing Then
 
Upvote 0
Ah - perhaps should have explained.

I get a "Expected procedure, not variable" error with the above code - highlighting the Else: Call UPDATE
 
Upvote 0
It should also be

Code:
Dim Prospectswb As Workbook, Workloadwb As Workbook, TGCwb As Workbook

Perhaps paste your UPDATE code.
 
Upvote 0
You are also missing an End If

Code:
Dim Prospectswb As Workbook, Workloadwb As Workbook, TGCwb As Workbook

Set Prospectswb = Workbooks("Prospects.xls")
Set Workloadwb = Workbooks("Workload.xls")
Set TGCwb = Workbooks("TGC.xls")

If Prospectswb Is Nothing Or Workloadwb Is Nothing Or TGCwb Is Nothing Then

    MsgBox ("Please make sure all workbooks are open and that they are named 'Prospects', 'Workload' and 'TGC' only")

Else
    Call Update
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,609
Messages
6,179,879
Members
452,948
Latest member
Dupuhini

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