Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2004
    Posts
    32

    Question Unanswered: Refrencing Excel from Access

    I am referencing an Excel file from within Access and I need the code to detect whether that particular file is currently open or not. I don't seem to be able to locate a property that will return this value. Does anyone know of one???

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    Here is a way you can do this

    Code:
    Sub testFunction()
        Dim mytest As Boolean
        mytest = xlOpenTest("K:\information\david\OP Activity.xls")
        MsgBox mytest
    End Sub
    
    Function xlOpenTest(wkbname) As Boolean
        Dim Xlapp As Excel.Application
        Dim Xlbook As Excel.Workbook
        
        Set Xlapp = Excel.Application
        
        Set Xlbook = Xlapp.Workbooks.Open(wkbname)
    
        'if an instance is already open then readonly = true
        If Xlbook.ReadOnly Then
            xlOpenTest = True
        Else
            xlOpenTest = False
        End If
        
        Xlbook.Close
        Xlapp.Quit
        On Error GoTo 0
        Set Xlbook = Nothing
        Set Xlapp = Nothing
    End Function
    make sure you have the microsoft excel object library referenced

    HTH
    Dave

Posting Permissions

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