Open WB Check. Need help to modify UDF.

TTom

Well-known Member
Joined
Jan 19, 2005
Messages
518
I'm using UDF below with Procedure to determine if WB is open; however, I want to check if ANY WB ending in:
"_TimeCard-Status_MASTER" is open. The WB being checked will always be in the name format:
YYYY-##_TimeCard-Status_MASTER
So, I want to ignore the left 7 characters of WB name when checking if a WB ending in "_TimeCard-Status_MASTER" is open.
I need help to modify my UDF or Procedure. See the line defining BName in my procedure.
Thanks for any help :wink: TTom
<code>
Dim myWbk As Boolean
Public Function IsBookOpen(BName As String) As Boolean
Dim WBk As Workbook
On Error Resume Next
If InStr(1, BName, ".xls", 1) = 0 Then BName = BName & ".xls"
Set WBk = Workbooks(BName)
IsBookOpen = (Err = 0) + 0
myWbk = IsBookOpen
End Function

Sub myWBopen()
BName = "-Status_MASTER" 'This is not complete WB name!!
IsBookOpen (BName)
If myWbk = True Then
MsgBox ("WB is Open")
Else:
MsgBox ("WB is Closed")
End If
End Sub
</code>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Answering my own question, FYI for my other BB friends...
No UDF required. Also, the Wb in question will end as: "_TimeCard-Status.xls"
<code>
Sub WBopenCheck()
Dim WBn$, x%, cnt%
cnt = Workbooks.Count
For x = 1 To cnt
WBn = Workbooks(x).Name
WBn = Right(WBn, 20)
If WBn = "_TimeCard-Status.xls" Then
MsgBox ("A TimeCard-Status WB is open")
End If
Next
End Sub
</code>
 
Upvote 0

Forum statistics

Threads
1,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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