Results 1 to 5 of 5

Thread: Excel 2013: How To Check How Many Excel Files Are Open

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    8
    Rep Power
    0

    Question Excel 2013: How To Check How Many Excel Files Are Open

    Hello,

    In previous Excel vba, I used "application.windows.count" to check how many Excel files are open.
    However, in Excel 2013, this script returns 1 no matter how many files are open.
    What vba script can I use to determine how many Excel files are open in Excel 2013?

  2. #2
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,401
    Rep Power
    10
    Try
    Code:
    application.workbooks.Count
    Or
    Code:
    Sub CountOpenWorkbooks()
    
        Dim wbk As Workbook
        Dim lng As Long
        
        For Each wbk In Workbooks
            If Not wbk.IsAddin Then
                lng = lng + 1
            End If
        Next wbk
        MsgBox "There are " & lng & " workbooks open", vbOKOnly, ""
    End Sub
    A dream is not something you see when you are asleep, but something you strive for when you are awake.

    It's usually a bad idea to say that something can't be done.

    The difference between dream and aim, is that one requires soundless sleep to see and the other requires sleepless efforts to achieve

    Join us at Facebook

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    8
    Rep Power
    0
    Thank you for your quick answer.
    Your script works fine in Excel vba.
    Now, I need to run this script from Powerpoint, and either of the scripts returns 0.

    Following is what I have written for your first answer:
    (I have Microsoft Excel 15.0 Object Library checked on Reference and a few Excel files open prior to running the script)

    Code:
    Dim exl as Excel.Application
    Dim wbct as integer
    Set exl = New Excel.Application
    exl.Visible = True
    wbct = exl.Application.Workbooks.Count  '<=  wbct returns 0
    Your second answer returned the same.

    What am I doing wrong?
    Last edited by Admin; 06-08-2013 at 08:51 AM.

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    try

    Code:
        Dim appExcel    As Excel.Application
        Dim Wbk         As Excel.Workbook
        Dim lngCount    As Long
        
        On Error Resume Next
        Set appExcel = GetObject(, "Excel.Application")
        On Error GoTo 0
        
        If appExcel Is Nothing Then
            MsgBox "There are no workbooks open", vbOKOnly
            Exit Sub
        Else
            For Each Wbk In appExcel.Workbooks
                If Not Wbk.IsAddin Then
                    lngCount = lngCount + 1
                End If
            Next
            
            MsgBox "There are " & lngCount & " workbooks open", vbOKOnly
        End If
    Last edited by Admin; 06-08-2013 at 08:54 AM.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Junior Member
    Join Date
    Jun 2013
    Posts
    8
    Rep Power
    0
    This worked perfectly.
    Tank you very much!

Similar Threads

  1. Good tutorial Excel 2013 SDK
    By Rasm in forum Excel Help
    Replies: 2
    Last Post: 04-01-2013, 01:17 AM
  2. Replies: 10
    Last Post: 12-10-2012, 11:28 PM
  3. Excel to Excel Data transfer without opening any of the files(source or target)
    By Transformer in forum Excel and VBA Tips and Tricks
    Replies: 14
    Last Post: 08-22-2012, 10:57 AM
  4. Loop and Check For Values In Entire Column in Excel
    By Jeff5019 in forum Excel Help
    Replies: 3
    Last Post: 05-01-2012, 10:34 PM
  5. Check if file is already open
    By Rasm in forum Excel Help
    Replies: 5
    Last Post: 11-24-2011, 04:55 PM

Tags for this Thread

Posting Permissions

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