View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default VBA - ThisWorkbook

If you use sheets("xxx") in a routine in a general module, then this sheet will
refer to the activeworkbook. It doesn't always refer to the workbook that owns
the code.

If you use sheets("xxx") in the ThisWorkbook module, then it will refer to the
object owning the code--ThisWorkbook.

I've never seen a difference in the way xl2003 and xl2007 works. I'd bet you're
mistaken. But since you didn't actually share a small snippet of code (and
where it was located), it's difficult to test.

Personally, I think you should qualify your objects--no matter where the code is
located or what version of excel you're using.

Jayashree Krishna wrote:

Hi,

In our VBA code we used Sheets("xxx") to refer to the data in the sheets in
the workbook which has the code. This worked well even if we open several
other workbooks thru that code. But suddenly, when we upgraded to Excel 2007,
this code no longer worked. Then we refered using ThisWorkbook.sheets("xxxx").

Can anybody know why "ThisWorkbook" keyword is not required in Excel 2003
VBA to refer to the sheets in the same workbook, whereas it is required in
Excel 2007 to refer to the sheets ?
Thanks,
Krishna


--

Dave Peterson