checking if some specific workbook is open; if not then it should be opened.

Sinem

Board Regular
Joined
Nov 8, 2015
Messages
63
Hello,


I want to write a code that checks if some specific workbook (wb2) is open already and if not then it should open wb2.
 
Hi Sinem

Thank you DocaElstein,

I your code works. Now I have this :

.....

I you not too good understand?

But thanks for the feed back and code :)

Alan

P.s. Please use code Tags when posting code:
To do that , highlight your code , then hit the # above

Code:
' Check if workbook is open
On Error Resume Next
Set wb1 = Workbooks(fname)
On Error GoTo 0
If wb1 Is Nothing Then
' If workbook was NOT open, it will open it
' it will use the parameter WbOpen to remember whether the workbook was open or not
Set wb1 = Workbooks.Open(fpath & "\" & fname, ReadOnly:=True) 
WbOpen = False
Else
' If the workbook was open, we'll just assign the sheet and WbOpen
WbOpen = True
End If 
' If the workbook was NOT open, close it with: If WbOpen = False Then daten.Close SaveChanges:=False




Rich (BB code):
' Check if workbook is open
On Error Resume Next
Set wb1 = Workbooks(fname)
On Error GoTo 0
If wb1 Is Nothing Then
' If workbook was NOT open, it will open it
' it will use the parameter WbOpen to remember whether the workbook was open or not
Set wb1 = Workbooks.Open(fpath & "\" & fname, ReadOnly:=True) 
WbOpen = False
Else
' If the workbook was open, we'll just assign the sheet and WbOpen
WbOpen = True
End If 
' If the workbook was NOT open, close it with: If WbOpen = False Then daten.Close SaveChanges:=False
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,215,756
Messages
6,126,691
Members
449,330
Latest member
ThatGuyCap

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