Results 1 to 3 of 3
  1. #1
    gixerp is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2016
    Location
    Essex UK
    Posts
    4

    Check if excel workbook is open

    How can I check if an excel workbook is open?



    I have a Frontend DB with linked tables to a Backend DB. This Backend DB also has a connection to an excel spreadsheet.
    On opening, the Frontend DB opens to a default form with various navigation buttons etc, one of which is to "Add a New Asset".
    Myself and another user (in another part of the country) have used this several times without any problems. . . until today.
    I was working on the excel workbook when the other user tried to Add a new Asset. After pressing the add new asset button the new form opened. . . but then froze. . everything.
    The only way to continue was to go into task manager and close Access completely.

    On investigation I found that it was because I had the excel workbook open.

    I therefore need to add something that checks to see if that (and one or two other) workbook/s is open. . . and tell the user to either close it, or wait till the other user has finished using it.

    Being a definite beginner, I have looked for a solution online, but most of the answers were in excel forums and not Access (is Excel & Access vba the same?). . . and didn't really cover my problem anyway.

    Any help is much appreciated.

    Thanks

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    excel and access vba are similar, but the way you reference things within them are not, but that is likely not going to affect the solution you found. if you post the code you found someone can likely pick it apart and adapt it for access.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I agree with rpeare....post your code.

    In the meantime, you might look at Ken Snell's site http://www.accessmvp.com/kdsnell/EXCEL_MainPage.htm

    If you click on the "Exporting" option, scroll down to the header "Write Data From a Recordset into an EXCEL Worksheet using Automation (VBA)", then look for the section of code that has a comment of " ' Establish an EXCEL application object"
    There is a check to see if a workbook is open:
    Code:
    <snip>
    ' Establish an EXCEL application object
    On Error Resume Next
    Set xlx = GetObject(, "Excel.Application")
    If Err.Number <> 0 Then
          Set xlx = CreateObject("Excel.Application")
          blnEXCEL = True
    End If
    Err.Clear
    On Error GoTo 0
    <snip>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 09-04-2013, 11:01 PM
  2. Replies: 1
    Last Post: 08-08-2013, 03:54 PM
  3. Replies: 5
    Last Post: 07-22-2013, 01:11 PM
  4. Replies: 6
    Last Post: 02-07-2013, 03:15 PM
  5. Replies: 4
    Last Post: 12-17-2012, 01:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums