Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
check to see if a file is open
I'm using the code below to display a dialog box for the user to select a file. I'm then checking to see if the file is opened. However, it appears the code is running faster than the file opens and I and getting the error message that the file was not opened when in fact it is. Is there a way to do slow down the code until the file is opened without coding a hard pause of X number of seconds? Any help or suggestion would be greatly appreciated. Thanks! FName = Application.GetOpenFilename If FName < False Then Workbooks.Open (FName) End If If Workbooks.Count < Wcount + 1 Then MsgBox "The file was not opened." Sheets("Macros").Activate End If code continues here....... -- JT |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
check to see if a file is open
Hi, Your code will pause at FName = Application.GetOpenFilename but a general method for checking if a workbook is open or not is Sub IsOpen() On Error Resume Next Set wBook = Workbooks(FName) If wBook Is Nothing Then 'Not open MsgBox "Workbook is not open", vbCritical Set wBook = Nothing On Error GoTo 0 Else 'It is open MsgBox "Yes it is open", vbInformation Set wBook = Nothing On Error GoTo 0 End If End Sub Mike "JT" wrote: I'm using the code below to display a dialog box for the user to select a file. I'm then checking to see if the file is opened. However, it appears the code is running faster than the file opens and I and getting the error message that the file was not opened when in fact it is. Is there a way to do slow down the code until the file is opened without coding a hard pause of X number of seconds? Any help or suggestion would be greatly appreciated. Thanks! FName = Application.GetOpenFilename If FName < False Then Workbooks.Open (FName) End If If Workbooks.Count < Wcount + 1 Then MsgBox "The file was not opened." Sheets("Macros").Activate End If code continues here....... -- JT |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Check if mdb file is open | Excel Programming | |||
How to check for Open File! | Excel Discussion (Misc queries) | |||
Check to see if a file is already open | Excel Programming | |||
File Open Check | Excel Programming | |||
check if file already is open | Excel Programming |