Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default File Open Check

I have an Excel spreadsheet that exports its date to Access when all my
macros are done running. It errors out if the database/file is open.

Is there a way to check to see if the datebase/file is open before I try to
export?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default File Open Check

Here is an example of some code to check it


Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long

On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0

Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select

End Function

Sub test()
If Not IsFileOpen("C:\MyTest\volker2.xls") Then
Workbooks.Open "C:\MyTest\volker2.xls"
End If
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"dthmtlgod" wrote in message
...
I have an Excel spreadsheet that exports its date to Access when all my
macros are done running. It errors out if the database/file is open.

Is there a way to check to see if the datebase/file is open before I try

to
export?




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
How to check for Open File! Ayo Excel Discussion (Misc queries) 2 August 11th 08 06:55 PM
check if file is already open mohavv Excel Discussion (Misc queries) 1 October 15th 07 12:08 AM
check if file with generic name already open Spike Excel Programming 2 November 25th 05 11:03 PM
check if file already is open Mats Nilsson Excel Programming 2 September 12th 05 09:30 AM
Check file open status kaon[_18_] Excel Programming 4 July 19th 04 05:16 AM


All times are GMT +1. The time now is 04:09 PM.

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

About Us

"It's about Microsoft Excel"