×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

C# - Visual Studio - Excel COM Add-In error...?

C# - Visual Studio - Excel COM Add-In error...?

C# - Visual Studio - Excel COM Add-In error...?

(OP)
I'm new to developing Excel AddIns with C#. I've been doing basic programming in VBA for a few years, but wanted to check out the C# capabilities. And I stumbled over this tutorial and tried it out.

https://docs.microsoft.com/en-us/visualstudio/vsto/walkthrough-creating-your-first-vsto-add-in-for-excel?view=vs-2019

I'm running Windows 10, MS Visual Studio Community 2019 (v. 16.2.2), and Excel for Office 365 MSO (16.0...) 32-bit.

The add-in is SUPPOSED TO create a simple COM AddIn for Excel, so when you save a Workbook, it inserts a new row at the top of the worksheet and adds a line of text / strings to the first cell.

I think I'm following the tutorial instructions correctly, but when I start debugging for the first time, I get the following error:

Quote (Visual Studio)

Severity Code Description Project File Line Suppression State
Error CS1061 'ThisAddIn' does not contain a definition for 'InternalStartup' and no accessible extension method 'InternalStartup' accepting a first argument of type 'ThisAddIn' could be found (are you missing a using directive or an assembly reference?) FirstExcelAddIn C:\Users\...\source\repos\FirstExcelAddIn\FirstExcelAddIn\ThisAddIn.Designer.cs 58 Active

I hover over that line of code and select, "Show potential fixes","Preview Changes", "Apply". And visual studio adds in this code:

CODE --> C#

private void InternalStartup()
        {
            throw new NotImplementedException();
        } 

I "Start" the debugger again. Visual Studio opens Excel. I open an excel workbook. Edit the workbook. Save the workbook. Close the workbook. And Visual Studio stops / ends the debugging without any error messages or warning.

Excel seems to be adding an instance of this new COM add-in to the add-ins manager (while I'm still in de-bugger mode), but it is NOT adding a row / text to the worksheet.

I'm at a loss to see what the error is, right now, does anyone see anything that I'm doing work? Or have some hints to point me in the right direction?

Thanks!

RE: C# - Visual Studio - Excel COM Add-In error...?

Howdy!
  1. Don't worry about InternalStartup. That's normal
  2. Are you using 64-Bit Office or 32-Bit? That's important
  3. Is your solution local or on a network drive? Addins need to be compiled and added locally
  4. I believe your code in Application_WorkbookBeforeSave is not quite OK
Application_WorkbookBeforeSave: I may be wrong, but I believe this is not going to work properly:

CODE

Excel.Worksheet activeWorksheet = ((Excel.Worksheet)Application.ActiveSheet); 

Why? Because you should tell Excel which object it is supposed to work with, e.g. like this:

CODE --> C#

var xl = Globals.ThisAddIn.Application;
Excel.Worksheet activeWorksheet = (Excel.Worksheet)xl.ActiveSheet; 

Hope, any of these help.

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: C# - Visual Studio - Excel COM Add-In error...?

Forgive me for posting off the topic, but what's "ACTA"? (I guess it's not "Affordable Care (Treacherous) Act"? smile )

Regards,

Ilya

RE: C# - Visual Studio - Excel COM Add-In error...?

Hi Ilya,

I though the other acronyms were explanatory enough:
ACTA
winky smile

"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.

RE: C# - Visual Studio - Excel COM Add-In error...?

Right!
Missed that, sorry!
Thanks!

Regards,

Ilya

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close