Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2016, 01:20 AM
Registered User
 
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default what is the difference between the WORKBOOKS & the WORKBOOK object?

As I understand it, the WORKBOOKS object is a collection of WORKBOOK objects. So I would have expected to see the WORKBOOK object contained within the WORKBOOKS object, but I don't. How come?

Other than using F2 in the VB Excel editor for documentation on the different classes, is there a more thorough site offered by MS that clearly shows the Excel hierarchy with the properties and methods. I know Java has something like that and would assume VBA Excel would as well; if so, where is it?

Thanks,
Dan

Last edited by bromberg; June 12th, 2016 at 01:23 AM..
 
Old June 15th, 2016, 02:00 AM
Authorized User
 
Join Date: Oct 2015
Posts: 48
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I am not sure if I get you correctly, if I do I think you got this wrong.
Workbook is a member of Workbooks collection.
Workbooks is in turn a list of all "open" Workbooks.
Codewise: if you create the collection you 1st need to initialise it, set it to Application.Workbooks.

Code:
Set WbCol = application.workbooks.
MyCount = WbCol.count.
Actually I'd avoid creating a collections variable if my program needs to be dynamic. I'd always call application.workbooks because the variable will not automatically update if any Workbooks are created after it is initialised.
Another thing to look at is the fact that if you manually create a Workbook it will not be added to the application.collection till you save it.

The key thing here is that it is a collection of "open" workbooks.
About a link I'll check if I still have some.
__________________
Nostalgia 4 Infinity
 
Old June 16th, 2016, 02:08 AM
Registered User
 
Join Date: Jun 2016
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default what is the difference between the WORKBOOKS & the WORKBOOK object?

You say that the Workbook object is a member of the Workbooks object but yet when I go here (the documentation I was hoping to discover):
https://msdn.microsoft.com/en-us/lib...ffice.14).aspx
it does not show the relation of Workbook to Workbooks.

Thank you for your suggestions in your reply, I wasn't aware of those "gotcha".
Dan
 
Old June 17th, 2016, 01:28 PM
Authorized User
 
Join Date: Oct 2015
Posts: 48
Thanks: 0
Thanked 5 Times in 5 Posts
Default

The relationship is Item. A specific open workbook is an Item in the in the workbooks collection.

Check this:
expression .Item(Index)

And this: https://msdn.microsoft.com/en-us/lib...ffice.14).aspx

Use Workbooks(index), where index is the workbook name or index number, to return a single Workbook object. The following example activates workbook one.
Code:
Workbooks(1).Activate
And this:
Code:
Workbooks("Cogs.xls").Worksheets("Sheet1").Activate
And this: https://msdn.microsoft.com/en-us/lib...ffice.14).aspx

This example sets the wb variable to the workbook for Myaddin.xla.
Code:
Set wb = Workbooks.Item("myaddin.xla")
In C++ terms: Is is more like having a class as a member of another class as opposed to an object of a class.
I suspect your mind kind of expects the 2 to have the same class structure.
__________________
Nostalgia 4 Infinity





Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between bytecode and object code? GPZ Java Basics 1 September 18th, 2017 05:40 AM
Difference between Instance and Object in # Manoj Bisht C# 9 August 26th, 2008 09:22 AM
Difference b/w declaring and using object keyword mjsoomro C# 3 March 11th, 2008 09:31 AM
Difference b/w Active X & Data Object bhasker_braj121 ADO.NET 0 June 19th, 2007 04:09 AM
Basic difference between + and & in strings shoakat Classic ASP Databases 1 October 27th, 2004 08:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.