VBA vs Object Oriented

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I can do the following

Workbooks("test1.xlsx").Worksheets("sheet1").Range("a1:b1") = "test"

to me that means "Worksheets" is a member of "Workbooks" class; otherwise excel would not accept:

Workbooks.Worksheets

But when I check the members of "Workbooks" class, I do not see Worksheets as a member? So why Workbooks.Worksheets is acceptable? Thank you indeed.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Workbooks("test1.xlsx") is a Workbook object... and not a Workbooks object which is a collection of Workbook objects

Workbooks <> Workbook
 
Last edited:
Upvote 0
Thanks for your reply.
I am a bit confused now because the website below mentioned the following:
"
A Workbook object can be accessed from the Workbooks Collection
"

To me that means Workbook is an object of Worksheets.
But I think you are right because Workbook has Worksheets

So the class is Workbook and the objects are Worksbooks and Worksheets which both inside Workbook. Am I right?
 
Upvote 0
Workbooks is the collection of workbooks currently open in the Excel session.

Workbooks(x) returns a member of that collection -- a workbook object.
 
Upvote 0

Forum statistics

Threads
1,224,745
Messages
6,180,699
Members
452,994
Latest member
Janick

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top