Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default VBA corruption

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
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




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
About Corruption Aqeel Ahmad Excel Discussion (Misc queries) 1 October 15th 09 05:19 PM
Spreadsheet Corruption? dennis[_2_] Excel Worksheet Functions 4 February 14th 09 12:37 PM
Spreadsheet Corruption? dennis[_2_] Excel Discussion (Misc queries) 2 February 14th 09 12:37 PM
formula corruption Graham Excel Worksheet Functions 1 December 15th 04 10:24 AM
Corruption? Mike Preston Excel Programming 2 September 2nd 03 04:28 PM


All times are GMT +1. The time now is 07:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"