JDaniluck
New Member
- Joined
- Feb 26, 2015
- Messages
- 12
Hey All,
This is my first question on this site. I use it all of the time by searching through the forums. So I thought I would finally join in the fun.
Anyhow, time for business. I am running into a problem with the "File in Use" alert.
I am attempting to write a code to automatically write data to a workbook in a shared location.
Every now and then this workbook in this shared location is in use by another person.
I have written a code to keep trying to open up the workbook in "Write" mode. However, When my code runs I get the "File in Use" message. I would like to add code into my workbook to automatically select "Read-Only" if I am prompted by the "File in Use" message.
So my overall goal is to open up this workbook in "write" mode, but if it opens up in "Read-Only" then I have the workbook close and then start again in 30 seconds. This repeats until I am able to open the workbook in "Write."
Any thoughts on how to control the "File in Use" alert?
Here is my code so far -
This is my first question on this site. I use it all of the time by searching through the forums. So I thought I would finally join in the fun.

Anyhow, time for business. I am running into a problem with the "File in Use" alert.
I am attempting to write a code to automatically write data to a workbook in a shared location.
Every now and then this workbook in this shared location is in use by another person.
I have written a code to keep trying to open up the workbook in "Write" mode. However, When my code runs I get the "File in Use" message. I would like to add code into my workbook to automatically select "Read-Only" if I am prompted by the "File in Use" message.
So my overall goal is to open up this workbook in "write" mode, but if it opens up in "Read-Only" then I have the workbook close and then start again in 30 seconds. This repeats until I am able to open the workbook in "Write."
Any thoughts on how to control the "File in Use" alert?
Here is my code so far -
Code:
Dim Myfile As Range
Dim NewFile As Variant
Dim WB1 As Workbooks
Dim RF As Worksheet
Set WB1 = Workbooks("Repair_Form.xlsm")
Set RF = WB1.Sheets("Repair_Form")
Set Myfile = RF.Range("AK4")
' Database Location
Workbooks.Open (Myfile.Value)
If Workbooks("Repair_Authorize_Database.xlsx").ReadOnly Then
Workbooks("Repair_Authorize_Database.xlsx").Close
CountDown_Timer.startCountDown
Exit Sub
Else
MsgBox "I made it :)"
End If
Workbooks("Repair_Authorize_Database.xlsx").Save
Workbooks("Repair_Authorize_Database.xlsx").Close
Exit Sub
ErrorHandle1:
MsgBox "I can not determine if the file is in Read Only"
Exit Sub
End Sub