View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Subscript out of range when adding worksheet

The only thing that seems like it might be amiss is that you are
not qualifying the Worksheets collection. Depending on the
location of the code (e.g., in the ThisWorkbook module), it is
using ThisWorkbook.Worksheets instead of
ActiveWorkbook.Worksheets.

Try changing the code to

ActiveWorkbook.Sheets.Add _

After:=ActiveWorkbook.Worksheets(ActiveWorkbook.Sh eets.Count)


Beyond that, it all looks good to me.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"RB Smissaert" wrote in message
...
Using Excel 97 to 2003.
I have an add-in that somewhere has to add a worksheet after

the last sheet.
This goes with:

ActiveWorkbook.Sheets.Add _
After:=Worksheets(ActiveWorkbook.Sheets.Count)

This goes fine with all the users of the add-in, except one

person, who gets
the error:
Subscript out of range
at this line.

I have tried all kind of manipulations such as deleting,

moving, renaming
and hiding of the sheets, but I just can't reproduce this

error. Protecting
the workbook will cause a different error.
I am just puzzeled what could be causing this error.
Any advice greatly appreciated.


RBS