Using C# to run VBA macro in Excel

J

John Mercure

I am trying to use C# to execute an Excel macro, via Excel.Application.Run.
The macro seems to launch, but hangs there. I am trying to do this while
Excel is invisible.

After encountering the hanging problem I decided to make Excel visible so I
could see what is happening. At this point I saw that Excel was just
freezing and not running the macro. However, if click on Excel the macro
takes off and completes successful.

The macro is performing a series of text replacements.

So my question is why would the macro hang in such a manner and how can I
emulate clicking Excel to get the macro to run.

Again the Workbook is being opened via C# and the macro is being launched
from C# using Excel.Application.Run.

- John Mercure
 
J

John Mercure

Some additional information here:

The macro is running, but slowly. I put 'Beep' calls in the macro, just to
give myself a clue as to whether or not the macros was running.

So my question is really this, why is it if Excel is running via automation
visible or not that some functions run extremely slow? However if I automate
with visibility and the click on Excel the macro runs at 'full' speed. This
makes no sense to me.

Is there someway to avoid this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top