0

We have a couple of spreadsheets here that we populate with some data and do some formatting using Microsoft.Office.Interop.Excel.

Now that part is all good - it's something along the lines of what is done here: Write to Excel example.

What I'd like to do is:

  • Add a button inside the spreadsheet, bound to a macro.
  • When the user clicks the button, the macro fires - we grab some parameters from the cells and pass those to the C# function. That code does all the heavy lifting, populates the spreadsheet as above, etc.

What I don't understand how to do is that second step - I can't see a way to actually pass parameters and call into C# directly. As it stands now, I can call a C# console application and pass command line parameters into it... but that seems a bit wrong, I'd have thought there would be some better way - but I can't seem to find it!

2
  • What about asking Google? Commented Mar 11, 2015 at 23:56
  • Do you own the C# code? If so, I think the only way is to register your assembly for COM interop. Check this. Commented Mar 12, 2015 at 2:22

1 Answer 1

1

Coopernick,

It looks like you need to develop an Excel add-in and move the VBA code on the add-in rails. See Walkthrough: Creating Your First Application-Level Add-in for Excel to get started quickly. You may consider an Excel add-in as a regular .Net application where you can use any components and libraries.

You may find the Excel Solutions section in MSDN helpful.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.