+ Reply to Thread
Results 1 to 2 of 2

File Open Check

Hybrid View

  1. #1
    dthmtlgod
    Guest

    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. #2
    Bob Phillips
    Guest

    Re: 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" <dvanderm@tcny.com> wrote in message
    news:%237sRo1EGGHA.3532@TK2MSFTNGP14.phx.gbl...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1