MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 27th, 2002, 11:35 AM   #1
John Bennito
New Member
 
Join Date: Feb 2002
Posts: 11
Default

How can I count the hidden workbooks and xla files that are open.

The workbooks.count only shows me the count for visible xls files
John Bennito is offline   Reply With Quote
Old Mar 27th, 2002, 11:46 AM   #2
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Hi,

Are you sure that hidden workbooks aren't being counted by Workbooks.Count? I just tried it on my machine and it included all of them.

Anyway, here's some code for getting the other bits you want. Hope it helps.

Code:
Sub GetCount()
Dim lngWorkbookCount As Long
Dim lngAvailableAddins As Long
Dim lngInstalledAddins As Long
Dim xlAddin As AddIn


lngWorkbookCount = Workbooks.Count
lngAvailableAddins = Excel.AddIns.Count

For Each xlAddin In Application.AddIns
    If xlAddin.Installed = True Then
        lngInstalledAddins = lngInstalledAddins + 1
    End If
Next


MsgBox "Workbooks open = " & lngWorkbookCount & vbCrLf & _
        "Available addins = " & lngAvailableAddins & vbCrLf & _
        "Installed addins = " & lngInstalledAddins

End Sub
dk is offline   Reply With Quote
Old Mar 27th, 2002, 11:59 AM   #3
John Bennito
New Member
 
Join Date: Feb 2002
Posts: 11
Default

Thanks DK

You may be right about the hidden files. However what I am really trying to count is open xla files. These files are not installed add-ins and when I ran your code this did not show up.

Any thoughts ?

Thanks

John
John Bennito is offline   Reply With Quote
Old Mar 27th, 2002, 12:03 PM   #4
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Quote:
--------------------------------------------------------------------------------
Thanks DK

You may be right about the hidden files. However what I am really trying to count is open xla files. These files are not installed add-ins and when I ran your code this did not show up.

Any thoughts ?

Thanks

John
Hi John,

The installed add-ins as per my code gives a count of the add-ins installed i.e. those which are ticked in the Tools, Addins dialog box. If you run the code and it says for example Installed add-ins=4 going into the VB editor and then looking in the project explorer you'll see 4 xla files.

Unless I've misunderstood your request I think this is what you were after. If not, please repost.

Regards,
Dan
dk is offline   Reply With Quote
Old Mar 27th, 2002, 12:52 PM   #5
John Bennito
New Member
 
Join Date: Feb 2002
Posts: 11
Default

Thanks DK
The xla file I am using is not an installed add-in. It does not show up in the Tools - add-in list in Excel.

It is just an xls file with VBA code that has been saved as an xla file.

I do not intend to make this an add-in as I need to distribute this file and also change it often.

Thanks

John


John Bennito is offline   Reply With Quote
Old Mar 27th, 2002, 01:15 PM   #6
Juan Pablo González
MrExcel MVP
 
Join Date: Feb 2002
Location: Bogota, Colombia
Posts: 11,927
Default

Excel only considers as an AddIn those files that are installed using the Tools, AddIns menu command. Your file is just a hidden workbook that has .xla as its extension.
__________________
Regards,

Juan Pablo González
http://www.juanpg.com
Juan Pablo González is offline   Reply With Quote
Old Oct 4th, 2010, 07:43 PM   #7
AGI VBA
New Member
 
Join Date: Oct 2010
Posts: 2
Thumbs up Re: Workbooks.count

I know this is an old post, but I've run into the same problem.

I'm working with a .xlam file I intend to make an add-in, but for now I've simply got the file open (and not added to Application.AddIns). I'm trying to write an installer macro that 1) closes the workbook, 2) copies the .xlam into the AddIns directory, 3) re-opens it, and 4) adds it to the AddIns collection. Running into problems on the second 'For...Next' loop below:


Code:
Dim fso As New FileSystemObject
Dim oFile
Dim strAddInLoc As String
Dim ThisAddin As String
Dim i As Integer


    'remove add-in from AddIns, if present
    For i = 1 To AddIns.Count
        If AddIns(i).Name = ThisAddin Then
            AddIns.Remove (i)
            Exit For
        End If
    Next i


    ' close add-in, if open
    For i = 1 To Workbooks.Count
        If Workbooks(i).Name = ThisAddin Then
            Workbooks(i).Close
            Exit For
        End If
    Next i


       'copy & re-open
        oFile.Copy strAddInLoc & oFile.Name, True
        Set oFile = fso.GetFile(strAddInLoc & oFile.Name)
        Workbooks.Open (oFile.Path)
        Workbooks(oFile.Name).IsAddin = True
   
       
    'install add-in
    With Application.AddIns
        .Add (oFile.Path)
        .Item(ThisAddin).Installed = True
    End With

But Workbooks.Count only returns a count of .xlsb/.xls/.xlsx/.xlsm, as far as I can tell. How can I get a count of ALL open workbooks, including AddIns (both Installed, and otherwise)?

Much appreciated!
AGI VBA is offline   Reply With Quote
Old Oct 4th, 2010, 08:32 PM   #8
AGI VBA
New Member
 
Join Date: Oct 2010
Posts: 2
Default Re: Workbooks.count

OK I've got an easy workaround, but it feels like there should be a more legitimate solution to this one....

Code:
On Error Resume Next
Workbooks(ThisAddIn).Close
On Error GoTo 0
AGI VBA is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 10:54 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes