Thread: VBA corruption
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default VBA corruption

I'm surprised that code ever worked!

Your "I" should be a sheet (or worksheet/chart) object


With ActiveWorkbook
..Worksheets.Add after:=.Sheets(.Sheets.Count)
End With

or
Set oSht = ActiveWorkbook.Sheets.Count
ActiveWorkbook.Worksheets.Add after:=oSht

Both the above add a new worksheet after all sheets (incl chart sheets). You
could of course change .Sheets.Count to a valid number, or Sheets to
Worksheets

Regards,
Peter T

"HSalim[MVP]" wrote in message
...
Hi,
I was working on some vba code - nothing complicated - adding a workbook,
then adding sheets and so on.
I could not tell why I kept getting errors adding a worksheet.
for example, Workbook.Worksheet.Add would work but .add(After:= I) would
result in an error.
would , eventually abandoned the file and started afresh and found that
the code works flawlessly.
That file was created in Xl2007 and saved as an xl2003 file. It is
running "in compatibility mode."

Is this a common occurrence? Any fixes?

HS