PC Review


Reply
Thread Tools Rate Thread

check to see if a file is open

 
 
JT
Guest
Posts: n/a
 
      6th Jul 2009

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 With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      6th Jul 2009

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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to check if file is already open? Kimmo Laine Microsoft C# .NET 2 31st May 2007 06:38 PM
Check to see if a file is already open =?Utf-8?B?SmFzb24gWmlzY2hrZQ==?= Microsoft Excel Programming 2 30th Jun 2006 08:56 AM
How to check if file is OPEN Alex Simic Microsoft VB .NET 4 30th Nov 2005 04:36 PM
vba to check presence of file and open/not open fLiPMoD£ Microsoft Excel Discussion 2 28th Apr 2005 08:14 PM
Check if file is open Randy Microsoft C# .NET 1 23rd Mar 2004 09:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:42 AM.