Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

justhumm

Technical User
Nov 30, 2018
6
0
0
US
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.

[URL unfurl="true"]https://docs.microsoft.com/en-us/visualstudio/vsto/walkthrough-creating-your-first-vsto-add-in-for-excel?view=vs-2019[/url]

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:

Visual Studio said:
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:
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!
 
Howdy!
[ol a]
[li]Don't worry about InternalStartup. That's normal[/li]
[li]Are you using 64-Bit Office or 32-Bit? That's important[/li]
[li]Is your solution local or on a network drive? Addins need to be compiled and added locally[/li]
[li]I believe your code in Application_WorkbookBeforeSave is not quite OK[/li]
[/ol]

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:
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.
 
Forgive me for posting off the topic, but what's "ACTA"? (I guess it's not "Affordable Care (Treacherous) Act"? :) )

Regards,

Ilya
 
Hi Ilya,

I though the other acronyms were explanatory enough:
ACTA
;-)

"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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top