ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check To see if file is open (https://www.excelbanter.com/excel-programming/406618-check-see-if-file-open.html)

Mark

Check To see if file is open
 
I have a form that tracks representative info and when "submitted" opens
another file and passes the data. There will be multiple users for the form,
and I want to have it setup so if 2 people hit submit at the same time, it
doesn't crash on one person with the data file open in a read only mode.

Workbooks.Open Filename:= _
"\\c:\Floor Support Question Logs\Question Log.csv",
WriteResPassword:="askme", IgnoreReadOnlyRecommended:=True

Sheets("question log").Select
Range("A1").Select

How would you check to see if the file is already open and if it is, loop
until it was closed before proceeding?

Thanks!



Mike H

Check To see if file is open
 
Mark,

To check if a workbook is open try this

Sub IsitOpen()
Dim WB As Workbook
On Error Resume Next
Set WB = Workbooks("mybook.xls")
If WB Is Nothing Then
MsgBox "Workbook is not open"
Set wBook = Nothing
On Error GoTo 0
Else
MsgBox "Yes it is open"
Set wBook = Nothing
On Error GoTo 0
End If
End Sub

Looping until it's closed is effectively putting your code into an endless
loop because there is no way of knowing fro how long the 'other' user
willhave it open so I would suggest you simply terminate your code with a
suitable message if the workbook os open.

Mike

"Mark" wrote:

I have a form that tracks representative info and when "submitted" opens
another file and passes the data. There will be multiple users for the form,
and I want to have it setup so if 2 people hit submit at the same time, it
doesn't crash on one person with the data file open in a read only mode.

Workbooks.Open Filename:= _
"\\c:\Floor Support Question Logs\Question Log.csv",
WriteResPassword:="askme", IgnoreReadOnlyRecommended:=True

Sheets("question log").Select
Range("A1").Select

How would you check to see if the file is already open and if it is, loop
until it was closed before proceeding?

Thanks!




All times are GMT +1. The time now is 12:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com