Determine If a Excel Workbook is Already Open

jonmelmo

New Member
Joined
Jun 29, 2022
Messages
2
I have this code to determine if a workbook is already open but having trouble figuring out to have it wait 5 seconds and try again and if after 3 tries then send the msgBox database is in use.


If wBook.ReadOnly = True Then
MsgBox "Database is in use. Please try after sometimes.", vbookonly + vbCritical, "error"

Exit Sub
End If
 

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.
This is a Do loop that repeats if the workbook is readOnly for 3 times. Search online for VBA examples of Wait functions that delay for a certain number of seconds and call that function in the commented part. Add the Wait function to the end of your code.
VBA Code:
Dim loopCount As Integer
loopCount = 0
Do
    loopCount = loopCount + 1
    If wBook.ReadOnly = True Then
        If loopCount > 2 Then
            MsgBox "Database is in use. Please try after sometimes.", vbOKOnly + vbCritical, "error"
            Exit Sub
        End If
        
        'Call function to delay 5 seconds
        
    Else
        Exit Do
    End If
Loop
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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