Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JT JT is offline
external usenet poster
 
Posts: 234
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if mdb file is open K[_2_] Excel Programming 2 December 24th 08 11:23 AM
How to check for Open File! Ayo Excel Discussion (Misc queries) 2 August 11th 08 06:55 PM
Check to see if a file is already open Jason Zischke Excel Programming 2 June 30th 06 08:56 AM
File Open Check dthmtlgod Excel Programming 1 January 13th 06 02:51 PM
check if file already is open Mats Nilsson Excel Programming 2 September 12th 05 09:30 AM


All times are GMT +1. The time now is 07:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"