Home » excel » excel – How to use Workbook Object

excel – How to use Workbook Object

Posted by: admin May 14, 2020 Leave a comment

Questions:

I want just get the workbook name. Why VBA returns a error when i try use Workbook´s Name property directly, like this:

MsgBox "workbook name = " & Workbook.Name

The compiler says: Variable not declared. Workbook is an object. Why do i have to declare a variable associated to it?

These work:

MsgBox "workbook name = " & ThisWorkbook.Name

MsgBox "workbook name = " & ActiveWorkbook.Name

Why do I have to use Application properties (ThisWorkbook and ActiveWorkbook) instead of Workbook.Name directly?

How to&Answers:

Workbook is not an object

Workbook is the class which represents all the workbooks,

(for more details: http://www.functionx.com/vbaexcel/topics/workbooks.htm)

and ThisWorkbook(or ActiveWorkbook) is the instance

classes don’t have values for properties (except static) .i.e. in other words, you cannot access instance variables through a class.

i hope you understand.