View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Michael D. Ober Michael D. Ober is offline
external usenet poster
 
Posts: 7
Default Reliably get sheet 1 of the active workbook

I have some VBA code that does the following:

Option Compare Text

for i = 1 to ActiveWorkBook.Worksheets(i)
if ActiveWorkBook.Worksheets(i).CodeName = "Sheet1" then
set ws = ActiveWorkBook.Worksheets(i)
exit for
end if
next i

The problem is that this code doesn't always return as expected. In the
debuger, it always works, when run from an Add-In menu item, it works about
10% of the time.

Any ideas,
Thanks,
Mike.