Checking if a workbooks is open

Carly

Active Member
Joined
Aug 21, 2002
Messages
370
Please could someone look at the code below as it doesn't seem to work:

If (Windows("MarginRecoveryPlan - TEMPLATE.xlsx").Activate Is Nothing) Then

Else

Workbooks.Open "\\Stoke\analytic$\Price Increase\MarginRecoveryPlan " & vMonth & "\Spreadsheets\MarginRecoveryPlan - TEMPLATE.xlsx"

End If

I am trying to check if the workbook is open & if not, open it.

Any help would be greatly received.

Kind Regards

Carly
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Hi Carly

You need something like this:

Code:
Dim wb As Workbook
 
On Error Resume Next
Set wb = Workbooks("YourWorkbookName.xls")
On Error Goto 0
 
If wb Is Nothing Then _
  Set wb = Workbooks.Open("C:\Folder\YourWorkbookName.xls")
 
Upvote 0
The above code helped, thank you very much...

I had already searched & got the code I had, which is why I needed some help as it didnt work.
 
Upvote 0
Hi,

I was wondering if someone could help me with another problem I'm having with this code:

Dim wb1 As Workbook
On Error Resume Next

Set wb1 = Workbooks("MarginRecoveryPlan - TEMPLATE.xlsx")

If wb1 Is Nothing Then
GoTo Z
End If

This code works fine for ages (as it is within a loop) checking that the spreadsheet is not there & jumping to Z, then twice in a row it finds the workbook & ignores the Go To Z bit fine, but when the next loop comes around the workbook is not there again but it won't go into the IF statement.

Is there anything else I need to go with it, anything else that could be stopping it setting it to nothing?

I appreciate this is only a very small piece of my code, but was just hoping someone would have a bright idea before I continued with my debugging.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,287
Members
452,902
Latest member
Knuddeluff

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