Calling an Excel macro from VB.NET

C

cr113

I just upgraded from Office 2000 to Office 2003. My VB.NET Excel macro
calls don't work any longer.

Here is how I make my Excel macro call from VB.NET:

Dim objExcel as Excel.Application

objExcel = New Excel.Application
objExcel.Workbooks.Open(FileName:="c:\test.xls", ReadOnly:=True)
objExcel.Run("test.xls!test.test")

I was using the COM object Microsoft Excel 9.0. I noticed that it has
been replaced by Microsoft Excel 11.0. I tried adding that as a
reference but now the Excel object is undefined.

Help!
 
J

Jim Hughes

Imports Microsoft.Office.Interop
'Add above to the top of class files using Excel object.
 
C

cr113

Jim said:
Imports Microsoft.Office.Interop
'Add above to the top of class files using Excel object.

That works but now there is another problem. There is a 15 second delay
from the time I call the macro until it actually gets executed. I've
already decided to switch back to 2000. I'm also going to rewrite all
my Excel macros. I'll probably use datagrids or something. Calling
macros is too flakey.

Do you know why the imports statement is required for Microsoft Excel
11.0 but not for Microsoft Excel 9.0? I still don't understand
namespaces...

Thanks!
 

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