thisworkbook and activebook access without usign workbooks collection

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
The code below is going to run no problem to my surprise. It will also run without typing Application. Now I am confused. I know to access a workbook I need to go through the workbook collection like the following

Code:
 msgbox(application.workbooks(1).name)

So why the code below is OK? Thank you very much.

Code:
Sub wk1()
   MsgBox (Application.ThisWorkbook.Name)
   MsgBox (Application.ActiveWorkbook.Name)
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You don't have to use Application when referencing the workbooks collection

This refers to the the workbook where this macro resides
msgbox Thisworkbook.name

refers to the workbook that is currently active. Could be the same
msgbox Activeworkbook.name

refers to the first opened workbook. Could be the same as either of the other two above.
msgbox Workbooks(1).name

Jeff
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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