简体   繁体   English

工作簿是 vba 中的 class 或 object?

[英]workbook is a class or object in vba?

I am new learner in vba.我是 vba 的新学员。 I am so confused in classes and object.我对课堂和 object 感到很困惑。 eg workbook is a class or object.例如,工作簿是 class 或 object。 Some one says that workbook is a class and someone says that workbook is a object.有人说工作簿是 class,有人说工作簿是 object。 If workbook is a object then object browser which is in vba shows that workbook is a class.如果工作簿是 object,则 vba 中的 object 浏览器会显示工作簿是 ZA2F2ED4F8EBC2CBB14C21A29DC40。

If I write- Dim wb as Workbook So here wb is what?如果我写- Dim wb as Workbook 那么这里的 wb 是什么? Workbook is what?工作簿是什么?

Please resolve my issue and thanks for advance.请解决我的问题并感谢您的提前。

It's both.两者都是。 A Class is a template, or definition, of an object; Class 是 object 的模板或定义; an object is an instance of a class. object 是 class 的一个实例。

Your 'wb' is - or will be - an object.您的“wb”是 - 或将是 - object。 After the code Dim wb as Workbook it is not anything, as nothing has been assigned to it, but it has been set up so that any object assigned to it must be a instance of class Workbook.在代码Dim wb as Workbook之后,它什么都不是,因为没有分配给它,但它已被设置,因此分配给它的任何 object 都必须是 class 工作簿的实例。 If you followed up you first line with something like wb = Workbooks(1) then wb would now represent a Workbook object.如果您在第一行跟进类似wb = Workbooks(1)的内容,那么 wb 现在将代表 Workbook object。 If, on the other hand, you tried something like wb = "I am a string" you'd get an error as the Dim said that it can only be a workbook.另一方面,如果您尝试wb = "I am a string"类的方法,则会收到错误,因为 Dim 说它只能是工作簿。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM