View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Mike S[_5_] Mike S[_5_] is offline
external usenet poster
 
Posts: 86
Default VBA vs C#: filling a spreadsheet with random numbers - C# 4xslower...

On 10/24/2010 9:10 AM, Hal Styli wrote:
Hello,

I have a VBA macro which fills a sheet with 65536 random integers, it
takes just over a minute to run on my laptop, a T5470 1.60 Dual Core
with 3.5GB Ram, running Vista, Excel 2007 and Visual Studio 2005. I
figured it might run faster in C#, in fact it runs 4 times slower and
then when you open the Spreadsheet, it complains about being in a
'different format than that specified in the file extension.... Verify
that the file is not corrupted..' - taking a long time to load,
perhaps another minute or two. Even given that the VBA is run from
within Excel, the C# version does seem extremely slow.

Is there anything fundamentally wrong with the C#?
Any tips on speeding it up?
Any way of making the format it is written to be 'straight xls',
rather than 'a different format.
A complete listing of the VBA sn the C# is given below.

Thanks for all constructive help given.
Hal


Have you seen this discussion?

http://www.eggheadcafe.com/software/...rough-com.aspx
-----------

Also would these lines help (did I miss them somewhere)?

m_objRange.Application.ScreenUpdating = false;
m_objRange.Application.EnableEvents = false;

http://stackoverflow.com/questions/3...-and-c-objects
-----------

Have you tried a trick I've seen here several times of looping backwards
instead of forwards?