Click here to Skip to main content
14,664,481 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello,

I have a problem, that I cannot solve. I've searched for it at goole and find nothing, that help me.
Here is my Problem:
I have to make histograms of particles by Excel 2003. There for I write a Program in C#, that automatically do that.The Interaction with Excel works very good. But when I want to make the histogramm with the Add-In "Analysis ToolPak" and the macro "histogram" the following Errocode is coming:

"runtime error 1004
ATPVBAEN.xla could not be found. Check the spelling of the filename, and verify that the file location is correct....."

I've found that the AddIn is installed, but when I open Excel with my Program, the AddIn isn't activated.
My question is, how can I activate this AddIn with my Programm.

Here is my Code-snippet, where I use the AddIn:

VBIDE.VBComponent oModule = workbook.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbext_ct_StdModule);
                    StringBuilder sb = new StringBuilder();

                    sb.Append("Sub Makro1()" + "\n");
                    sb.Append("  Application.Run" + " \"ATPVBAEN.XLA!Histogram\", " + "ActiveSheet.Range(\"$C$2:$C$" + (letzte_zeile - zeile_eins + 2) + "\") _" +"\n");
                    sb.Append("     , ActiveSheet.Range(\"$F$2:$O$54\"), ActiveSheet.Range(\"$D$2:$D$43\"), False, _" + "\n");
                    sb.Append("     True, True, False" + "\n");
                    sb.Append("End Sub");

                    String scode = sb.ToString();
                    oModule.CodeModule.AddFromString(scode);
                    workbook.Application.Run("Makro1", missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);

In the last line the error occures.

I hope you understand, what I want.

Greeting from me
Posted
Comments
Maciej Los 31-May-11 15:14pm
   
First of all it's not good idea to add code to the workbook. Antivirus program can treat it as a virus code.

Before i make an answer i need to know how you create your workbook: by Interop services or using OLE Automation? Addin is installed (on the computer) or installed in MS Excel? What you see in Addin menager?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

The Workbook already exist and I open it.
Excel.Workbook workbook = excel.Workbooks.Open(filename+"test.xls", missing, missing, missing,
                missing, missing, missing, missing, missing, missing, missing, missing, missing,
                missing, missing);


I use the Interop services.
The Addin-Manager displays always the same. It says that the Addin is installed and activated, but under "extra" the "Data analysis" doesn't exist.
Here is a picture of the Addin-Manager.
picture
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100