Active Workbook

  • Thread starter Thread starter Tendresse
  • Start date Start date
T

Tendresse

Hello all,
I'm a bit confused on when we need to use the 'ActiveWorkbook' keyword when
writing VBA code. For example, to unprotect a sheet, i normally use the
statement:

ActiveSheet.Unprotect

I'm wondering if that's good enough or I am supposed to go one level up by
referring to the workbook the activesheet belongs to, eg:

ActiveWorkbook.ActiveSheet.Unprotect

I'm using Excel 2003.
Many thanks in advance
Tendresse
 
Hello all,
I'm a bit confused on when we need to use the 'ActiveWorkbook' keyword when
writing VBA code. For example, to unprotect a sheet, i normally use the
statement:

ActiveSheet.Unprotect

I'm wondering if that's good enough or I am supposed to go one level up by
referring to the workbook the activesheet belongs to, eg:

ActiveWorkbook.ActiveSheet.Unprotect

I'm using Excel 2003.
Many thanks in advance
Tendresse

Hi Tendresse

As far as i know Excel assumes Activeworkbook and Activesheet if you
omit them.
With your example for unprotecting it therefore doesn't matter if you
put the activeworkbook or not, on the other hand the activesheet is
needed because you have to tell excel what you want to unprotect.
If you take an expression like range you can write like that:
activeworkbook.activesheet.range
activesheet.range
or just
range
it's all the same.

hope that helps

Carlo
 
Thanks for your help, Carlo. Much Appreciated.

carlo said:
Hi Tendresse

As far as i know Excel assumes Activeworkbook and Activesheet if you
omit them.
With your example for unprotecting it therefore doesn't matter if you
put the activeworkbook or not, on the other hand the activesheet is
needed because you have to tell excel what you want to unprotect.
If you take an expression like range you can write like that:
activeworkbook.activesheet.range
activesheet.range
or just
range
it's all the same.

hope that helps

Carlo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top