call excel macro from asp page

B

berkeleydb_user

Hi

Am new to asp.net programming. I need to call a excel macro from asp
page. I got this code from msdn site,. The code compiles but I run I
don't see the results of macro execution. I don't get any error. I am
calling a simple macro that sets the value of active cell in default
sheet to something. Here is the code and macro.

Excel.Application m_objExcel = new Excel.ApplicationClass();
m_objExcel.Visible = false;

Excel._Workbook wb = m_objExcel.Workbooks.Open(fName, Missing.Value,
Missing.Value,
Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value);

m_objExcel.GetType().InvokeMember("Run",
System.Reflection.BindingFlags.Default |
System.Reflection.BindingFlags.InvokeMethod, null, m_objExcel,
new Object[] {"firstmacro"});

wb.Close(false, Missing.Value, Missing.Value);

m_objExcel.Workbooks.Close();
m_objExcel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject (m_objExcel);
System.Runtime.InteropServices.Marshal.ReleaseComObject (wb);

wb = null;
m_objExcel = null;

GC.Collect();


Here is the macro.

Public Sub firstmacro()
ActiveCell.Value2 = 101
End Sub

I made sure the Security settings of macros are set to 'Low'.

Please help.

thanks very much
 
B

berkeleydb_user

Guys

after spending grueling 3 days with this issue I found the solution
myself. And I found it a minute after posting the question here..

This is the only change I had to do...asp was running the macro but it
wasn't saving the changes in excel. so for wb.close(), i gave 'save'
argument as true and it worked.

wb.Close(true, Missing.Value, Missing.Value);

i see many postings on web for this problem with no solution. here is
the solution.

have fun.
 

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