+ Reply to Thread
Results 1 to 8 of 8

Open workbook Count

  1. #1
    Hervinder
    Guest

    Open workbook Count


    I am trying to write a simple code within an existing macro that tells me
    how many workbooks are open at any one time.

    I can do counting sheets which would be

    shts = activeworkbook.sheets.count

    i cant seem to apply the same principle with open workbooks.

    thank you
    hervinder

  2. #2
    Norman Jones
    Guest

    Re: Open workbook Count

    Hi Hervinder,

    Try:

    MsgBox Application.Workbooks.Count


    ---
    Regards,
    Norman



    "Hervinder" <[email protected]> wrote in message
    news:[email protected]...
    >
    > I am trying to write a simple code within an existing macro that tells me
    > how many workbooks are open at any one time.
    >
    > I can do counting sheets which would be
    >
    > shts = activeworkbook.sheets.count
    >
    > i cant seem to apply the same principle with open workbooks.
    >
    > thank you
    > hervinder




  3. #3
    Ardus Petus
    Guest

    Re: Open workbook Count

    nWB = Workbooks.Count

    HTH
    --
    AP

    "Hervinder" <[email protected]> a écrit dans le message de
    news: [email protected]...
    >
    > I am trying to write a simple code within an existing macro that tells me
    > how many workbooks are open at any one time.
    >
    > I can do counting sheets which would be
    >
    > shts = activeworkbook.sheets.count
    >
    > i cant seem to apply the same principle with open workbooks.
    >
    > thank you
    > hervinder




  4. #4
    Andrew Taylor
    Guest

    Re: Open workbook Count

    Use Workbooks.Count


    Hervinder wrote:
    > I am trying to write a simple code within an existing macro that tells me
    > how many workbooks are open at any one time.
    >
    > I can do counting sheets which would be
    >
    > shts = activeworkbook.sheets.count
    >
    > i cant seem to apply the same principle with open workbooks.
    >
    > thank you
    > hervinder



  5. #5
    Bob Phillips
    Guest

    Re: Open workbook Count

    Use Workbooks.Count, but be aware it will count Personal.xls if you have
    one, and any other files in XLStart that get opened automatically.

    --
    HTH

    Bob Phillips

    (remove xxx from email address if mailing direct)

    "Hervinder" <[email protected]> wrote in message
    news:[email protected]...
    >
    > I am trying to write a simple code within an existing macro that tells me
    > how many workbooks are open at any one time.
    >
    > I can do counting sheets which would be
    >
    > shts = activeworkbook.sheets.count
    >
    > i cant seem to apply the same principle with open workbooks.
    >
    > thank you
    > hervinder




  6. #6
    Bob Phillips
    Guest

    Re: Open workbook Count

    Use Workbooks.Count, but be aware it will count Personal.xls if you have
    one, and any other files in XLStart that get opened automatically.

    --
    HTH

    Bob Phillips

    (remove xxx from email address if mailing direct)

    "Hervinder" <[email protected]> wrote in message
    news:[email protected]...
    >
    > I am trying to write a simple code within an existing macro that tells me
    > how many workbooks are open at any one time.
    >
    > I can do counting sheets which would be
    >
    > shts = activeworkbook.sheets.count
    >
    > i cant seem to apply the same principle with open workbooks.
    >
    > thank you
    > hervinder




  7. #7
    Forum Contributor
    Join Date
    03-24-2004
    Location
    Edam Netherlands
    Posts
    181
    Dim wkbBook as Workbook
    Dim lCount as long
    For each wkbBook in Application.Workbooks
    if wkbBook.Windows(1).visible Then lCount = lCount + 1
    next wkbBook

  8. #8
    Chip Pearson
    Guest

    Re: Open workbook Count

    Try the following function:


    Function WorkbookCount(Optional VisibleOnly As Boolean = False)
    Dim WB As Workbook
    If VisibleOnly = True Then
    For Each WB In Workbooks
    If WB.Windows(1).Visible = True Then
    WorkbookCount = WorkbookCount + 1
    End If
    Next WB
    Else
    WorkbookCount = Workbooks.Count
    End If
    End Function


    You can then use it in code like

    If WorkbookCount(VisibleOnly:=False) > 1 Then


    --
    Cordially,
    Chip Pearson
    Microsoft MVP - Excel
    Pearson Software Consulting, LLC
    www.cpearson.com






    "Hervinder" <[email protected]> wrote in
    message
    news:[email protected]...
    >
    > I am trying to write a simple code within an existing macro
    > that tells me
    > how many workbooks are open at any one time.
    >
    > I can do counting sheets which would be
    >
    > shts = activeworkbook.sheets.count
    >
    > i cant seem to apply the same principle with open workbooks.
    >
    > thank you
    > hervinder




+ 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